【问题标题】:How do you manage the events in a UINavigationController view to switch views?您如何管理 UINavigationController 视图中的事件以切换视图?
【发布时间】:2011-04-07 23:23:02
【问题描述】:

我有一个 UINavigationController w/三个视图和 UINavigationBar 中每个视图的关联按钮。由于我是 XCode 的新手,因此我试图了解将事件处理代码放置在何处以管理视图之间的切换。

视图 A(根)

转到视图 B(按钮)

查看 B

返回(按钮)转到视图 C(按钮)

查看C

返回(按钮)

我知道如何在单击“转到视图 B”时捕获事件,但由于该按钮是在视图 A 中创建的,因此它无法访问 UINavigationController 来切换视图。

感谢任何示例或指向其他信息的链接。

【问题讨论】:

标签: xcode ios uinavigationcontroller


【解决方案1】:

如果我正确理解您的问题,请查看:

UINavigationControllerDelegate:http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationControllerDelegate_Protocol/Reference/Reference.html

UINavigationBarDelegate:http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationBarDelegate_Protocol/Reference/Reference.html

如果您只是尝试使用 navigationController 推送新视图,就这么简单(在您的 GoToViewB 按钮/操作中):

YourNewViewController *yourNewViewController = [[YourNewViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:yourNewViewController animated:YES];
[yourNewViewController release];

现在你应该在你的 newViewController 中,它会有一个返回按钮来返回上一个视图。您可以使用与上述相同的逻辑转到下一个视图等。如果您想以编程方式弹出控制器,您可以使用:

[self.navigationController popViewControllerAnimated:YES];

【讨论】:

  • 问题是 self.navigationController 不在按钮及其事件处理程序所在的视图控制器的范围内。我了解在导航控制器中对视图的操作,只是导航控制器在对象层次结构中比包含按钮和处理程序的视图高一级。
  • 相对于视图 A、B 和 C,您的 navController 在哪里?
  • 请参阅上面的评论以获取带有详细代码的新问题的链接。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 2012-03-18
  • 1970-01-01
相关资源
最近更新 更多