Reputation: 205
I loaded a new view controller successfully with this IBAction that is triggered when a button is clicked.
-(IBAction)changeToAnotherView:(id)sender
{
if (self.newController == nil)
{
newController = [[UIViewController alloc] initWithNibName:@"NewViewController" bundle:[NSBundle mainBundle]];
}
quizController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:newController animated:YES completion:NULL];
}
However, my function to return to the old view in NewViewController.m does not build. Why?
- (IBAction)goBackToOldView:(id)sender
{
[self dismissWithClickedButtonIndex:0 animated:YES];
}
The build error I get is "No visible interface declares dismissWithClickedButtonIndex:animated:".
Update:
lldb now outputs
"2012-04-30 21:31:56.530 Project32[10105:fb03] -[UIViewController goBackToOldView:]: unrecognized selector sent to instance 0x6c57f20
2012-04-30 21:31:56.531 Project32[10105:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController goBackToOldView:]: unrecognized selector sent to instance 0x6c57f20'
*** First throw call stack:
(0x1649052 0x1bfdd0a 0x164aced 0x15aff00 0x15afce2 0x164aec9 0x2d05c2 0x50bd54 0x164aec9 0x2d05c2 0x2d055a 0x375b76 0x37603f 0x3752fe 0x2f5a30 0x2f5c56 0x2dc384 0x2cfaa9 0x2536fa9 0x161d1c5 0x1582022 0x158090a 0x157fdb4 0x157fccb 0x2535879 0x253593e 0x2cda9b 0x217d 0x20e5)
terminate called throwing an exception(lldb)"
Interestingly, I implemented goBackToOldView
in NewViewController:
- (IBAction)goBackToOldView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
Upvotes: 2
Views: 865
Reputation: 2670
Change your code to the following and it should dismiss correctly.
-(IBAction)changeToAnotherView:(id)sender
{
if (self.newController == nil)
{
newController = [[UIViewController alloc] initWithNibName:@"NewViewController" bundle:[NSBundle mainBundle]];
}
quizController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:newController animated:YES];
}
- (IBAction)goBackToOldView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
Hope this helps!
Upvotes: 2
Reputation: 13459
Because that is not the correct function, it should be.
[self dismissViewControllerAnimated:YES completion:Nil];
(You can replace the nil on completition for a block to perform something after the controller has been dismissed.)
Upvotes: 3