Sha*_*ade 9 delegates uitabbarcontroller ios
我有一个UITabBarController,我已经设置了它的委托方法didSelectViewController
,因为我对正在选择的选项卡的索引感兴趣.
但是,我注意到didSelectViewController
当用户处于"更多"部分时(当标签栏中显示的标签多于标签栏时),该方法不会被调用:
有没有办法让我收到用户从正在自动创建的表中选择的项目的通知?
我在这个问题上找到了我需要的东西.
基本上,您为"更多"选项卡中显示的导航控制器设置了a UITabBarControllerDelegate
和 a UINavigationControllerDelegate
.之后,您将检测用户是否触摸了其中一个可见选项卡或"更多"选项卡.
编辑
此外,要直接操作"更多"导航控制器中可见的表,您可以设置"中间人"表视图委托,该委托拦截对原始委托的调用.请参阅didSelectViewController
下面的代码:
if (viewController == tabBarController.moreNavigationController && tabBarController.moreNavigationController.delegate == nil) {
// here we replace the "More" tab table delegate with our own implementation
// this allows us to replace viewControllers seamlessly
UITableView *view = (UITableView *)self.tabBarController.moreNavigationController.topViewController.view;
self.originalDelegate = view.delegate;
view.delegate = self;
}
Run Code Online (Sandbox Code Playgroud)
之后,只要在另一个委托中调用相同的方法,您就可以自由地在委托方法中执行任何操作(我实际上检查了原始委托响应的方法,并且实现的唯一委托方法是didSelectRow:forIndexPath:
).请参阅以下示例:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// this is the delegate for the "More" tab table
// it intercepts any touches and replaces the selected view controller if needed
// then, it calls the original delegate to preserve the behavior of the "More" tab
// do whatever here
// and call the original delegate afterwards
[self.originalDelegate tableView: tableView didSelectRowAtIndexPath: indexPath];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3868 次 |
最近记录: |