didSelectViewController在“更多”中不被调用部分 [英] didSelectViewController not getting called when in "More" section

查看:160
本文介绍了didSelectViewController在“更多”中不被调用部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITabBarController,我已经设置了它的委托方法 didSelectViewController ,因为我对选择的选项卡的索引感兴趣。

I have a UITabBarController and I have set up its delegate method didSelectViewController, as I am interested in the index of the tab that is being selected.

但是,我注意到,当用户位于更多部分(当有更多)部分时,不会调用 didSelectViewController 方法更多的标签可以在标签栏中显示):

However, I noticed that the didSelectViewController method doesn't get called when the user is in the "More" section (when there are more tabs than can be shown in the tabbar):

有没有办法让我从用户自动创建的表中收到用户选择的项目?

Is there a way for me to get notified of the items the user selects from the table that is being automatically created?

推荐答案

我发现我需要在

I found what I needed in this question.

基本上你设置了一个 UITabBarControllerDelegate a 用于导航控制器的UINavigationControllerDelegate 在更多选项卡中显示。之后,您可以检测到用户是否触及其中一个可见的标签页或更多标签。

Basically you set up a UITabBarControllerDelegate and a UINavigationControllerDelegate for the navigation controller that is displayed inside the More tab. After that you detect if the user touched one of the visible tabs, or the "More" tab.

编辑

另外,为了直接操作更多导航控制器中可见的表,您可以设置一个中间人表视图委托,拦截对原始委托的调用。请参阅 didSelectViewController 以内的代码:

Also, to directly manipulate the table that is visible within the "More" navigation controller, you can set up a "man-in-the-middle" table view delegate, that intercepts the calls to the original delegate. See code from inside didSelectViewController below:

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;
}

之后,你可以自由地在委托方法中做任何你喜欢的事情,只要你在其他委托中调用相同的方法(我实际上检查了原来的代理回复的方法,而唯一的代理方法是 didSelectRow:forIndexPath:)。见下面的例子:

After that, you are free to do whatever you like inside the delegate methods, as long as you call the same methods in the other delegate (I actually checked to which methods the original delegate responds, and the only delegate method that is implemented is the didSelectRow:forIndexPath:). See an example below:

- (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];
}

这篇关于didSelectViewController在“更多”中不被调用部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆