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

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

问题描述

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

但是,我注意到 didselectviewontroller 方法在更多"部分中没有被调用(当有更多的标签时,在Tabbar中可以显示):

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

解决方案

我在 这个问题.

基本上,您为更多选项卡中显示的导航控制器设置了 UITabBarControllerDelegate UINavigationControllerDelegate.之后,您可以检测用户是否触摸了其中一个可见选项卡或更多"选项卡.

编辑

另外,要直接操作在更多"导航控制器中可见的表格,您可以设置一个中间人"表格视图委托,它会拦截对原始委托的调用.请参阅下面 didSelectViewController 内部的代码:

if (viewController == tabBarController.moreNavigationController && tabBarController.moreNavigationController.delegate == nil) {//这里我们用我们自己的实现替换更多"选项卡表委托//这允许我们无缝替换视图控制器UITableView *view = (UITableView *)self.tabBarController.moreNavigationController.topViewController.view;self.originalDelegate = view.delegate;view.delegate = 自我;}

之后,您可以在委托方法中自由地做任何您喜欢的事情,只要您在另一个委托中调用相同的方法(我实际上检查了原始委托响应的方法,以及唯一的委托方法实现的是 didSelectRow:forIndexPath:).请参阅下面的示例:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {//这是更多"选项卡表的委托//如果需要,它会拦截任何触摸并替换选定的视图控制器//然后,它调用原始委托以保留更多"选项卡的行为//在这里做任何事情//然后调用原始委托[self.originalDelegate tableView: tableView didSelectRowAtIndexPath: indexPath];}

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.

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.

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.

EDIT

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

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天全站免登陆