【发布时间】:2014-11-29 18:46:04
【问题描述】:
在使用带有 initWithNavigationBarClass:toolbarClass 的 NavigationController 设置时,如何在 rootViewController 中为 CustomToolbar 设置委托:
在我的代码中,我正在执行以下操作:
RootViewController *rootViewController = [[RootViewController alloc] initWithClassName:kFTPostClassKey];
UINavigationController *navController = [[UINavigationController alloc] initWithNavigationBarClass:[CustomNavigationBar class] toolbarClass:[CustomToolbar class]];
[navController setViewControllers:@[rootViewController] animated:NO];
// Present the Home View Controller
[self presentViewController:navController animated:YES completion:NULL];
在“RootViewController”中,我正在尝试为工具栏设置委托,以便检测何时点击项目。
[self.navigationController.toolbar setDelegate:self];
当我这样做时,我得到一个异常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot manually set the delegate on a UIToolbar managed by a controller.'
我查看了文档并了解到当工具栏由 UINavigationController 管理时,您无法设置委托。我的问题是:如果无法设置委托,如何检测 RootViewController 中 CustomToolbar 上的点击?
我也希望得到更深入的解释,因为我是新手,不知道这一切是如何运作的。
【问题讨论】:
标签: ios objective-c uinavigationcontroller delegates uitoolbar