This is an iOS5 and ARC specific question.
I was setting up a set of UIViews inside a UIScrollView, each with their own UIButton declared inside the UIView class:
IBOutlet UIButton*button;
@property(nonatomic,strong) UIButton*button;
(I also original had this as a retain instead of strong, but it made no difference)
I also synthesize the button and hook it up in IB to:
-(IBAction)showArticle:(id)sender;
I add them all to the scroll view with a big loop, depending on the type of article:
NewsScrollLead*view = [[NewsScrollLead alloc]initWithNibName:@"NewsScrollLead" bundle:nil];
[view.view setFrame:CGRectMake(0, 0, 513, 225)];
[view.titleLabel setText:[newsDict objectForKey:@"title"]];
[view.details setText:[self flattenHTML:[newsDict objectForKey:@"description"]]];
[view.source setText:[newsDict objectForKey:@"author"]];
[view.details setFont:[UIFont fontWithName:@"HelveticaNeue-Condensed" size:14]];
[view.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-BoldCond" size:20]];
[view.source setFont:[UIFont fontWithName:@"HelveticaNeue-Condensed" size:14]];
[self.newsScrollView addSubview:view.view];
This is one example of how a view is created and added to the scroll view.
When I try to click on a button, I get an unrecognized selector error from something different each time, not a UIButton. Using NSZombie, the button has been deallocated for some reason.
Any ideas? Pre-iOS5 issues of the same type were resolved by retaining the UIButton, or the view it was contained in, but with ARC there is no retain available.
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, view.view.frame.size.width, view.view.frame.size.height)];
[button setTag:i];
[button addTarget:self action:@selector(presentArticle:) forControlEvents:UIControlEventTouchUpInside];
[view.view addSubview:button];
[view setButton:button];
This fixes the issue, the buttons are never dealloc'd, but is not a true answer to the question. - Matt Foley