I have an application in which I need to be able to update what buttons may appear on the home screen and have elected to use core data to allow me to update the controlling property via XML. The core data seems to be working well and updating, and the buttons are being created, however, for some reason, the selector doesn't seem to be retained as it crashes every time I click on the button. The error log doesn't say anything - except one time when it did say "unrecognized selector sent to instance". Here is the method I use to create the buttons:
- (void)setUpNavigationButtons {
int i = 0;
for (Features *myFeature in self.features) {
CGRect buttonRect = [self makeFeatureButtonFrame:[self.features count] withMember:i];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aButton setFrame:buttonRect];
[aButton addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTitle:[NSString stringWithFormat:@"%@",myFeature.name] forState:UIControlStateNormal];
[self.view addSubview:aButton];
i++;
}
}
Here is the the selector method, in the same view controller class:
- (void)buttonTouched:(id)sender{
NSLog(@"feature selected");
}
Any help is much appreciated. Please let me know if more of the code is required to ascertain anything meaningful. I don't want to ask folks to read through a mountain of it if only a molehill is required.
UPDATE: 4/27/2011 In response to the comments in the checked answer below, I am posting the code that launches the view controller. I've not had a problem with this in the past, but it's entirely possible I've picked up some bad technique in here. This is from the method application:didFinishLaunchingWithOptions method in the AppDelegate. Anyway, here is the code:
UINavigationController *navigationController = [[[UINavigationController alloc] init] autorelease];
HomeViewController *root = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
root.title = companyName;
root.context = [self managedObjectContext];
[navigationController pushViewController:root animated:NO];
[window addSubview:navigationController.view];
[root release];
[self.window makeKeyAndVisible];
return YES;