UINavigationController 与 popToRootViewController 的问题
假设我在视图控制器 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的要求是转换到视图控制器 D(或
voteView
),那么当您调用
setViewControllers:
并访问索引 1 处的对象时,您应该执行与您的问题相关的 操作,你确保数组有两个对象吗?您将NSLog
放入了voteView
的哪个方法中?If your ask is to transition to View Controller D (or
voteView
), you should be doing-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 ofvoteView
did you put theNSLog
?