美文网首页iOS Developer
iOS开发点滴-UITabBarController页面之间跳转

iOS开发点滴-UITabBarController页面之间跳转

作者: DreamMmMmM | 来源:发表于2016-11-22 15:02 被阅读190次

有时候会遇见像淘宝购物那种,买完东西后继续购物会跳转到主页,用push和pop是不行的 ,

这时我们需要考虑到 self.tabBarController.selectedIndex 这个属性

这个属性是当前UITabBarController 对应页面的index索引

所以你只需要设置self.tabBarController.selectedIndex = 0(或者你需要跳转页面的索引) 这样一句就可以了

如果你的UITabBarController 是self.window.rootViewController 你可以在AppDelegate文件内添加通知观察者


[[NSNotificationCenterdefaultCenter]  addObserver:selfselector:@selector(changeTabBar:) name:@"NOTIFICATION_CHANGE_TABBAR"object:nil];

-(void)changeTabBar:(Notification *)notif {

intindex = [[notif object] intValue];

UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;

if(tabVC) {

tabVC.selectedIndex = index;

}

}

在购物车中点“再逛逛”按钮回到首页


[[NSNotificationCenterdefaultCenter] postNotificationName:@"NOTIFICATION_CHANGE_TABBAR"object:@(0)];

相关文章

网友评论

    本文标题:iOS开发点滴-UITabBarController页面之间跳转

    本文链接:https://www.haomeiwen.com/subject/olnppttx.html