I’m trying to show a UIView subclass with:
-(void)pushChatNewMessage:(id)sender
{
NSNotification *not = (NSNotification *)sender;
NSNumber *num = (NSNumber *)not.object;
OTChatMessageBox *chatMessageBox = [[OTChatMessageBox alloc] init];
chatMessageBox.frame = CGRectMake(123, 60, 778, 208);
chatMessageBox.toId = [num intValue];
[UIView beginAnimations:@"animationChatBox" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:chatMessageBox cache:YES];
[self.view addSubview:chatMessageBox];
[UIView commitAnimations];
[chatMessageBox release];
}
The problem is that I’m getting this error:
modifiying layer that is being finalized
I observed in debug that the dealloc method of the OTChatMessageBox object is called just ends this method.
If I remove the release of the object, all works fine…with a great leak…
I reviewed the init method of OTChatMessageBox and is absolutely simple, only a textView object and a button with a notification call.
What I’m missing?
Thanks in advance 😉
–EDIT–
-(id)init
{
self = [super init];
if (self)
{
self = [[[NSBundle mainBundle] loadNibNamed:@"OTChatMessageBox" owner:self options:nil] objectAtIndex:0];
[txtMessage becomeFirstResponder];
}
return self;
}
loadNibNamed:returns anautorelease‘dNSArrayof objects. Therefore yourOTChatMessageBoxisautorelease‘d when you get it fromalloc/init. This means that your endreleaseis causing an overrelease. The problem is that theinitmethod should return an object which the caller is expected to take ownership over.The
self = [super init];is a memory leak as you never use the returned object and you don’t release it, as you havealloc‘d the object already you should at release it. In this case you would need something likeThis is of course a needless
alloc/initand you may wish to rethink how you are doing this