开发者

Push to another view with UIBarButtonSystemItemAdd

I am trying to 开发者_JAVA百科edit the add button to push to another view. But I am receiving an error

-(void)locationAdd:(id)sender{
 if([self.parentViewController isKindOfClass:[UINavigationController class]]){
  UINavigationController *parent = (UINavigationController *)self.parentViewController;
  if ([[parent viewControllers] objectAtIndex:0] == self) { 
   LocationsAddViewController *alocationAddViewController = [[[LocationsAddViewController alloc] initWithNibName:@"LocationAddView" bundle:[NSBundle mainBundle]] autorelease];
   //self.locationAddViewController = alocationAddViewController;
   alocationAddViewController.title = @"Toevoegen";
   [self.parentViewController pushViewController:alocationAddViewController animated:YES];
  }
  else if([[parent viewControllers] objectAtIndex:2] == self){
   LocationsAddViewController *alocationAddViewController = [[[LocationsAddViewController alloc] initWithNibName:@"LocationAddView" bundle:[NSBundle mainBundle]] autorelease];
   alocationAddViewController.title = @"Toevoegen";
   [self.parentViewController pushViewController:alocationAddViewController animated:YES];
  }
 }
}

Because the view can be reached from 2 other views and it has to look different, I have used

if([self.parentViewController isKindOfClass:[UINavigationController class]]){
        UINavigationController *parent = (UINavigationController *)self.parentViewController;
        if ([[parent viewControllers] objectAtIndex:0] == self) {   

to check where it comes from.

The problem is at: [self.parentViewController pushViewController:alocationAddViewController animated:YES]; I am receiving the error:

+[LocationsTableViewController pushViewController:animated:]: unrecognized selector sent to class 0x23510 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[LocationsTableViewController pushViewController:animated:]: unrecognized selector sent to class 0x23510'

Can someone help me? What did I do wrong?


Your error indicates that you're trying to call pushViewController:animated: on your LocationsTableViewController class object. This shouldn't be possible given the code you posted. Are you sure you pasted in the exact code that threw the exception? (It's suspicious that your if and else if blocks do the exact same thing.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜