0

我几乎在所有应用程序中都这样做了,但是我在 navigationController 中有 3 个视图堆叠,我需要从第三个视图跳转到第一个视图。据我了解,我只能通过 viewWillDisappear 做到这一点。但是,如果我尝试这种“跳转”,我将从第二个视图中获得 navigationController 面板,该面板带有导致异常/错误的导航按钮。

PS 不要建议我让 leftBarButtonitem 看起来像 backBarButtonItem。这太难了,我不知道在哪里可以找到合适的图像。

4

2 回答 2

0

To my knowledge, you have no choice but to provide your own UIBarButtonItem. You are not permitted from interrupting how UINavigationController works by default. That is, you cannot override the behavior of the back button. You must provide a custom bar button item and set it as the navigation item's left bar button item.

(As a side note, the sort of behavior you're looking for may be an indication of a poor navigation pattern. Back buttons should almost always back out of a navigation hierarchy sequentially.)

于 2011-09-14T07:22:00.847 回答
0

假设按照导航顺序,您的视图堆叠为 top -> 3 -> 2 -> 1 。当您处于此位置时,您的应用程序委托中可以有一个标志,显示当按下 backButton 时您将 doublePop 如下所示:(每当第三个视图按您提到的顺序出现时,您都在执行此操作)

MyApplicationDelegate * del = [[UIApplication sharedApplication]delegate];
del.doublePopEnabled = YES;
[del release];

在视图 2 中:

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
         MyApplicationDelegate * del = [[UIApplication sharedApplication]delegate];
         if(del.doublePopEnabled){
           //Asssuming you have a reference to your navigationController in your view 2
           del.doublePopEnabled = NO;
           [del.release]
           //Use animated as no if you don't want user to see doublePopping.
           self.navigationController popViewControllerAnimated:NO];

          }
 }

希望能帮助到你。

于 2011-09-14T08:51:57.580 回答