导航栏BackButton不能正常工作

问题描述:

我有一个“FairListViewController”。这是第一个ViewController。在这里通过触摸tableCell,我可以去下一个是“MenuViewController”。并且有两个按钮,“ProductViewController”的“Product”和“EventViewController”的“Events”。我在我的appDelegate中使用“NavigationController”作为“rootViewController”。现在,当我触摸“MenuViewController”中的“产品”按钮时,将我带到“ProductViewController”并触摸“BackButton”,然后顺利返回到“MenuViewController”。我为“ProductViewController”做了相同的代码,在这里它将我带到“EventViewController”,但在触摸“BackButton”之后,很奇怪的是它返回到“FairListViewController”的第一页。我改变了我的IBAction按钮名称的名字(在“EventViewController”nib文件中)几次&与nib文件重新连接,甚至从nib文件中删除按钮并尝试用新按钮,但结果是一样的!以前可以有任何一个类似这个问题。任何建议都将非常可观。非常感谢Advance。导航栏BackButton不能正常工作

这里是我的代码:

IN MenuViewController(对于ProductViewController按钮):

- (IBAction)callProductGroups:(id)sender 
{ 
ProductGroupViewController *productGroupViewController; 

if(IS_IPHONE_5) 
{ 
    productGroupViewController = [[ProductGroupViewController alloc] initWithNibName:@"ProductGroupViewController" bundle:nil]; 
} 
else 
{ 
    productGroupViewController = [[ProductGroupViewController alloc] initWithNibName:@"ProductGroupViewControlleriPhone4" bundle:nil]; 
} 

productGroupViewController.topBarImageForAll = self.topBarImageForAll; 
productGroupViewController.topBarButtonImageForAll = self.topBarButtonImageForAll; 
productGroupViewController.buttonDividerImageForAll = self.buttonDividerImageForAll; 
productGroupViewController.backgroundImageForAll = self.backgroundImageForAll; 
productGroupViewController.backgroundImageiPhone4ForAll = self.backgroundImageiPhone4ForAll; 

[self.navigationController pushViewController:productGroupViewController animated:YES]; 
} 

在ProductViewController:

-(IBAction)goBack:(id)sender 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

在MenuViewController(对于EventViewController按钮) :

- (IBAction)callEvents:(id)sender 
{ 
EventViewController *eventViewController; 

if (IS_IPHONE_5) 
{ 
    eventViewController=[[EventViewController alloc] initWithNibName:@"EventViewController" bundle:nil]; 
} 
else 
{ 
    eventViewController=[[EventViewController alloc] initWithNibName:@"EventViewControlleriPhone4" bundle:nil]; 
} 

eventViewController.topBarImageForAll = self.topBarImageForAll; 
eventViewController.topBarButtonImageForAll = self.topBarButtonImageForAll; 
eventViewController.buttonDividerImageForAll = self.buttonDividerImageForAll; 
eventViewController.backgroundImageForAll = self.backgroundImageForAll; 
eventViewController.backgroundImageiPhone4ForAll = self.backgroundImageiPhone4ForAll; 

[self.navigationController pushViewController:eventViewController animated:YES];  
} 

在EvenViewController:

- (IBAction)backButton:(id)sender 
{ 
    [self.navigationController popToRootViewControllerAnimated:YES]; 
} 

[有没有打算下一个视图控制器的问题,这个问题是关于回来了。]

+1

因为您发送' popToRootViewControllerAnimated:'。 – cahn

+0

但我发送同样的东西到“ProductViewController”,但它正常支持。我应该发送什么?我是iOS新手,很抱歉像这样提问。 @chan – Tulon

+0

是的,我明白了。我错过了这个区别。它是一个愚蠢的东西。感谢您的评论。 :) – Tulon

Try instead of 
    [self.navigationController popToRootViewControllerAnimated:YES]; 

Use 
    [self.navigationController popViewControllerAnimated:YES]; 
+0

是的,我明白了。我错过了这个区别。这是一个愚蠢的错误。感谢您的评论。 :) – Tulon