有时候会遇见像淘宝购物那种,买完东西后继续购物会跳转到主页,用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)];
网友评论