UINavigationController 与 popToRootViewController 的问题

发布于 2024-12-08 21:02:09 字数 1044 浏览 0 评论 0原文

假设我在视图控制器 C 中,我想转换到视图控制器 D(这里是 voteView)。这就是我所做的:

VoteViewController * voteView = [[VoteViewController alloc] init];
        voteView.voteInfo = [array objectAtIndex:0];

    NSArray * viewControllers = [self.navigationController viewControllers];
    if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
        NSLog(@"LIST VIEW");
    } else if ([[viewControllers objectAtIndex:0] isKindOfClass:[SpotListingViewController class]]){
        NSLog(@"SPOT LISTING");
    }

    [self.navigationController setViewControllers:[NSArray arrayWithObjects:[viewControllers objectAtIndex:0], [viewControllers objectAtIndex:1], voteView, nil]];
    [voteView release];

运行上面的代码,它会打印 LIST VIEW,这意味着 RootViewController 是一个 ListViewController。现在理论上在 VoteViewController 中,当我执行以下操作时:

 if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
            NSLog(@"LIST VIEW");

它应该打印列表视图,但事实并非如此。这是为什么呢?我还检查了视图控制器的计数,它只有 2。为什么不一样?

So lets say that I am in viewcontroller, C and I want to transition to viewcontroller D (which is voteView here). So here's what I did:

VoteViewController * voteView = [[VoteViewController alloc] init];
        voteView.voteInfo = [array objectAtIndex:0];

    NSArray * viewControllers = [self.navigationController viewControllers];
    if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
        NSLog(@"LIST VIEW");
    } else if ([[viewControllers objectAtIndex:0] isKindOfClass:[SpotListingViewController class]]){
        NSLog(@"SPOT LISTING");
    }

    [self.navigationController setViewControllers:[NSArray arrayWithObjects:[viewControllers objectAtIndex:0], [viewControllers objectAtIndex:1], voteView, nil]];
    [voteView release];

Running the code above, it prints LIST VIEW, which means that the RootViewController is a ListViewController. Now theoritically at VoteViewController when I do as below:

 if ([[viewControllers objectAtIndex:0] isKindOfClass:[ListViewController class]]){
            NSLog(@"LIST VIEW");

it should print LIST VIEW, however it doesn't. Why is this? I also checked the count of the view controller and it's only 2. Why is it different?

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

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

发布评论

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

评论(1

独夜无伴 2024-12-15 21:02:09

如果您的要求是转换到视图控制器 D(或 voteView),

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

那么当您调用 setViewControllers: 并访问索引 1 处的对象时,您应该执行与您的问题相关的 操作,你确保数组有两个对象吗?您将 NSLog 放入了 voteView 的哪个方法中?

If your ask is to transition to View Controller D (or voteView), you should be doing-

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

Related to your question, when you call setViewControllers: and access object at index 1, have you ensured that the array has two objects? In which method of voteView did you put the NSLog?

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