首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS: On 'Automatic TabBar switched‘方法

iOS: On 'Automatic TabBar switched‘方法
EN

Stack Overflow用户
提问于 2012-08-22 02:41:45
回答 2查看 311关注 0票数 0

我尝试以编程方式切换选项卡,并确保在切换时,相应的导航控制器弹出到根视图控制器。有没有在手动或编程切换选项卡栏时调用的方法?

注意:只有在手动切换选项卡栏时才会调用-(void)tabBarController:didSelectViewController:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-22 02:52:25

您也可以尝试以编程方式调用didSelectViewController。在这里查看babbidi的答案:

How to trigger method "tabBarController:didSelectViewController:" programmatically?

票数 1
EN

Stack Overflow用户

发布于 2012-08-22 03:52:07

另一种方式是在selectedViewController上使用观察者。

代码语言:javascript
复制
// Add Observer
// Note: tabBarController.selectedIndex is not observed as it does not call observeValueForKeyPath on manual switch
[self.tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:@"changedTabbarIndex"];

// Method for Handling Observations
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSString *action = (__bridge NSString*)context;
    if([action isEqualToString:@"changedTabbarIndex"])
    {
        // Stuff to do on selected Tab changed
    }
}

// Change selectedViewController
[self.tabBarController setSelectedViewController:[[self.tabBarController viewControllers] objectAtIndex:kSomeTab]];

更多信息:I didn't get any notifications when I touched on tabbar items

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12061073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档