Reputation: 32091
This is a very simple issue but I have no idea why it's happening. In my header file, I've declared a UIButton *leftButton
. In the viewDidLoad method I do this leftButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
Then in some other method I have:
leftButton.frame=newFrame;
leftButton.tag=i;
[leftButton addTarget:self action:@selector(leftButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:leftButton];
However I keep getting a crash when the above method is called. Sometimes I get a message, other times it just crashes with no message. I can't really replicate any crash messages, now all I'm getting is just a general crash, but it kept crashing from weird issues such as [UIGestureRecognizer setFrame] is causing problems or [WebView setFrame] or something..for some reason it keeps thinking that leftButton is something else than a UIButton, but this is not the case. There is nothing else named leftButton in my entire project. Any ideas?
Upvotes: 3
Views: 561
Reputation: 119292
Your first method is returning an autoreleased object, most likely it has been released by the time your second method is called. Either retain the button in the first method or use a retained property to hold on to it rather than an ivar.
Also, remember to release this in your dealloc method at the end.
Upvotes: 7