簡體   English   中英

導航欄BackButton不能正常工作

[英]Navigation Bar BackButton doesn't work perfectly

我有一個“ FairListViewController”。 這是第一個ViewController。 在這里,通過觸摸tableCell,我可以轉到下一個菜單“ MenuViewController”。 並且有兩個按鈕,“ Product”代表“ ProductViewController”,“ Events”代表“ EventViewController”。 我在appDelegate中將“ NavigationController”用作“ rootViewController”。 現在,當我觸摸“ MenuViewController”中的“產品”按鈕時,將我帶到“ ProductViewController”並觸摸“ BackButton”,它會平滑地回到“ MenuViewController”。 我為“ ProductViewController”執行了相同的代碼,在這里將我帶到“ EventViewController”,但是在觸摸“ BackButton”后,奇怪的是它返回到第一頁,即“ FairListViewController”。 我多次更改了IBAction按鈕名稱的名稱(在“ EventViewController” nib文件中)並重新連接了nib文件,甚至從nib文件中刪除了該按鈕並嘗試了一個新按鈕,但是結果是一樣的! 以前有誰能解決這個問題。 任何建議都是非常可取的。 非常感謝預先。

這是我的代碼:

在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];
}

[轉到下一個ViewController沒問題,問題在於返回。]

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

Use
    [self.navigationController popViewControllerAnimated:YES];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM