Touchupinside and simple viewController question
I've got a very simple viewController question .
I've got a main view with 2 buttons, upon touchupinside of a button I would like to load a new view Controller ( a table view ) .
I've created a new viewController with its nib file .
Created an IBAction like this that I've linked the button to in IB :
- (IBAction)displayVin {
UIViewController *vinController = [[UIViewController alloc] initWithNibName:@"vinController" bundle:nil];
[self.navigationContro开发者_StackOverflowller pushViewController:vinController animated:YES];
[vinController release];
}
It's not doing anything therefore I must be forgetting something, but what ? should I declare this newViewController somewhere else ? It's compiling and executing fine with no error message .
UPDATE:
I'm now using this :
- (IBAction)displayVin:(id)sender {
NSLog(@"here");
UIViewController *vinController = [[UIViewController alloc] initWithNibName:@"vinController" bundle:nil];
[self.navigationController pushViewController:vinController animated:YES];
[vinController release];
}
But it's crashing with this error when I press the button :
[displayVin]: unrecognized selector sent to instance 0x8d03000 ** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[displayVin]: unrecognized selector sent to instance 0x8d03000'*
Should I be declaring something somewhere else , or "should" that bit of code be enough ?
Start by using NSLog() to determine if you're actually inside the displayVin() routine. Button events send a parameter to the acion, so you should probably declare it as -(IBAction)displayVin:(id)sender
instead of just -(IBAction)displayVin
.
For your updated code, you might have to reconnect the IBOutlet in the IB file. It looks like it's still calling the [viewController displayVin] method (without arguments), instead of the [viewController displayVin:]
精彩评论