【问题标题】:UINavigationController - PopUINavigationController - 弹出
【发布时间】:2011-09-11 16:03:05
【问题描述】:

我在从导航堆栈中弹出项目时遇到了一些问题,不知道为什么会这样。

Stack
A classA
B classB
C classC
D classD

在堆栈 D 中,我创建另一个 classD 并将其添加到堆栈中。

Stack
A classA
B classB
C classC
D classD
E classD

在创建 E 并将其压入堆栈之前,我会执行弹出操作以摆脱 D 以便堆栈变为

Stack
A classA
B classB
C classC
E classD

但是,当我弹出时,self.navigationController.viewcontrollers 变为 0,并且我卡在 C 上,而 E 不可见。为什么pop只是删除所有内容并转到C?

在 didSelectRowAtIndexPath 的 C 中,我创建了一个 ClassD 并执行以下操作:

[self.navigationController pushViewController:ClassD animated:YES];

在 didSelectRowAtIndexPath 中的 D 处,我创建了另一个 ClassD 并执行以下操作:

[self.navigationController popViewControllerAnimated:NO]; //remove current and replace with new
[self.navigationController pushViewController:ClassD animated:YES];

但它似乎没有按预期做。我感觉从 pop 到 push 的过渡似乎太快了,什么都没有出现?有任何想法吗?

【问题讨论】:

    标签: iphone ios uinavigationcontroller


    【解决方案1】:

    听起来popViewController 也将self.navigationController 设置为nil。如果self.navigationControllernil 那么[self.navigationController anyMethod] 什么都不做。

    试试这个(未测试):

    UINavigationController *nav = self.navigationController;
    
    [nav popViewControllerAnimated:NO]; //this pops myself
    [nav pushViewController:anotherInstanceOfClassD animated:YES];
    

    如果是 causes the problem that self is beeing destroyed,那么只需在 pop 之前添加以下行:

    [[self retain] autorelease]
    

    【讨论】:

    • 这似乎奏效了。感谢您提供更多信息的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 2010-12-05
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    相关资源
    最近更新 更多