更详细地解释我的应用程序布局:单击表视图的任何行,用户将进入下一个屏幕,返回按钮指向主页,顶部有一个分段控件。代码中的逻辑确定分段控制的哪些段将被预先选择。用户可以点击分段控件的任何索引来改变显示在屏幕上的内容。
我实现上述布局的方式是通过一个导航控制器。与分段控件的“第一、第二和第三”相对应的每个页面的内容都是单独的视图控制器。我采用这种方式的原因是因为这些页面中的每一个都有重要的功能和控件供用户交互。将它们分别作为单独的视图控制器有助于软件代码组织和数据完整性。主屏幕位于导航控制器堆栈的索引0处,视图控制器对应于导航控制器中的索引1处的第一个,等等。假设用户当前在第二个屏幕上,在分段控件中选择了“first”。如果用户现在点击"third",两个视图控制器将被推入堆栈,反之亦然,用于将控制器弹出导航堆栈。
两个问题:·对我的实现方式有什么评论吗?有没有更好的实现建议?我确实考虑过的一个具体实现是,一个视图控制器可以有三个独立的视图(第一、第二和第三个视图各一个)?对这种方法有什么评论吗?
• I seem to have an extremely hard time controlling the behavior of the “back button”of the navigation controller. When the user has selected “second”in the segmented control, I would still like to have the back button saying “Home” instead of “first” which is the default behavior of the navigation controller. I have figured out how I can customize the text of the back button. However, I can't seem to figure out how to customize the behavior of the button. What I mean by that is, when the user is on "third”, and clicks on the “home button”I'd like to pop three view controllers and land the user on the home screen.因此,我看到并尝试了各种技术,但都没有成功:方法1: viewwillDisappear():确定此函数是否作为后退按钮按下的一部分被调用,并实现在标准视图控制器弹出之外弹出其他视图控制器的逻辑。有一段时间,这个逻辑确实弹回了主页,但它立即崩溃了,并显示了以下消息,我似乎不太明白:
方法2: didPopItem():我将以下代码放入此函数中
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item {
NSLog(@"%s",__FUNCTION__);
[[self navigationController] popViewControllerAnimated:YES];
//ViewControllerAnimated:YES];
NSLog(@"navcount%d",self.navigationController.viewControllers.count);
if (self.navigationController.viewControllers.count > 1) {
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
}如对以上内容有任何意见,我们将不胜感激!提前感谢您的帮助。
发布于 2012-04-21 12:52:11
由于三个视图控制器在视图层次结构中实际上彼此相等,因此我建议您在切换段时替换顶部视图控制器,而不是推入多个视图控制器,这样您就可以从三个视图控制器中的任何一个“返回”,并最终到达您想要的位置。
这样的东西对你来说应该是有效的:
- (void)replaceTopViewControllerWith:(UIViewController *)vc {
NSMutableArray *vcs = [[self.navigationController viewControllers] mutableCopy];
[vcs removeLastObject];
[vcs addObject:vc];
[self.navigationController setViewControllers:vcs animated:YES];
}https://stackoverflow.com/questions/10255742
复制相似问题