UINavigationController - 流行

发布于 2024-12-04 04:28:30 字数 913 浏览 1 评论 0原文

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

Stack
A classA
B classB
C classC
D classD

在堆栈 DI 中创建另一个 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];

但它似乎没有按预期执行操作。我感觉从流行到推送的转变似乎太快了,什么也没有出现?有什么想法吗?

I am having some problems with popping items from the navigation stack and no idea why its behaving like it is.

Stack
A classA
B classB
C classC
D classD

At stack D I create another classD and add it to the stack.

Stack
A classA
B classB
C classC
D classD
E classD

Before I create E and push it on to the stack, I do a pop to get rid of D so that the stack becomes

Stack
A classA
B classB
C classC
E classD

However when I pop, the self.navigationController.viewcontrollers becomes 0 and im stuck on C with E not becoming visible. Why does the pop just remove everything and go to C?

At C in didSelectRowAtIndexPath I create a ClassD and do:

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

At D in didSelectRowAtIndexPath I create another ClassD and do:

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

But it doesn't seem to do what as expected. I sense the transition from pop to push seems to be too fast nothing is appearing? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

<逆流佳人身旁 2024-12-11 04:28:30

听起来 popViewController 也将 self.navigationController 设置为 nil。如果 self.navigationController 为 nil,则 [self.navigationController anyMethod] 不执行任何操作。

试试这个(未测试):

UINavigationController *nav = self.navigationController;

[nav popViewControllerAnimated:NO]; //this pops myself
[nav pushViewController:anotherInstanceOfClassD animated:YES];

如果这个 导致 self 被破坏的问题 然后只需在 pop 之前添加以下行:

[[self retain] autorelease]

it sounds like the popViewController is also setting the self.navigationController to nil. if self.navigationController is nil then [self.navigationController anyMethod] does nothing.

try this (not tested):

UINavigationController *nav = self.navigationController;

[nav popViewControllerAnimated:NO]; //this pops myself
[nav pushViewController:anotherInstanceOfClassD animated:YES];

if this causes the problem that self is beeing destroyed then just add the following line before pop:

[[self retain] autorelease]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文