ios uitabbarcontroller 双击tabbaritem ,popToRootViewController的问题
2014-03-18 23:21
796 查看
这个问题困惑了一阵。。。查阅资料也无果,突然灵感来了。。就试试,果断好使用,就记录下来,以分享;cheers;
本文环境: ios7.03 模拟器, arc;
xcode:5.02
如果。。。你用形如 :
uinavigationcontroller *nav1 =[[uinavigationcontroller alloc] initwithrootviewcontroller :[[uiviewcontroller alloc ] init]];
uinavigationcontroller *nav2 =[[uinavigationcontroller alloc] initwithrootviewcontroller :[[uiviewcontroller alloc ] init]];
nsarray *navAray =[nsarray arraywithobjects:nav1,nav2,nil];
uitabbarviewcontroller *rotbar =[uitabbarviewcontrolelr alloc] init];
rotbar.delegate =self;
[rotbar setviewcontrollers: navAray];
self.window.rootviewcontroller =rotbar;
然后,你在点击tabbaritem 的时候,要判断那个viewcontroller 的内容是否为空,是空值就要跳转到下一个viewcontrolelr;
一切到看起来很好;但是如果是双击tabbaritem;tabbarcontroller 有个默认属性,如果当前的视图控制器有navigationcontroller;就默认popToRootViewcontroller;
比较烦人;
在这里,用这个方式来实现:就能很好的处理这个问题。
实现tabbarcongtroller的代理:
这是在模拟器下 自定义的代码:
shuaxinviewcontroller 就是第一个vc ;
nextviewcontroller 就是第二个vc;
gotoNextviewcontroller就是挑战判断;
关键是这句代码:
[tabBarController setSelectedViewController:viewController];
你大概一下子就醒悟了.....
//另外模拟器和真机的实际,稍稍有些不同,请自己调试;
-(bool)tabbarviewcontrolelr:(uitabbarviewcontrolelr *)tabbarcontroller shouldSelectViewcontroler:(uiviewcontroller)viewcontrolelr{
if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *nav =(UINavigationController *)viewController;
if (nav.viewControllers.count ==1) {
[(ShuaXinViewController *)(nav.viewControllers[0]) gotoNextViewController:nil];
[tabBarController setSelectedViewController:viewController];
return NO;
}else{
if (nav.viewControllers.count ==2) {
if ([nav.topViewController isKindOfClass:[nextViewController class]]) {
[tabBarController setSelectedViewController:viewController];
return NO;
}
}
}
}
return YES;
}
PS: 手敲的。。。不要在意细节,拼写,符号,请忽略
本文环境: ios7.03 模拟器, arc;
xcode:5.02
如果。。。你用形如 :
uinavigationcontroller *nav1 =[[uinavigationcontroller alloc] initwithrootviewcontroller :[[uiviewcontroller alloc ] init]];
uinavigationcontroller *nav2 =[[uinavigationcontroller alloc] initwithrootviewcontroller :[[uiviewcontroller alloc ] init]];
nsarray *navAray =[nsarray arraywithobjects:nav1,nav2,nil];
uitabbarviewcontroller *rotbar =[uitabbarviewcontrolelr alloc] init];
rotbar.delegate =self;
[rotbar setviewcontrollers: navAray];
self.window.rootviewcontroller =rotbar;
然后,你在点击tabbaritem 的时候,要判断那个viewcontroller 的内容是否为空,是空值就要跳转到下一个viewcontrolelr;
一切到看起来很好;但是如果是双击tabbaritem;tabbarcontroller 有个默认属性,如果当前的视图控制器有navigationcontroller;就默认popToRootViewcontroller;
比较烦人;
在这里,用这个方式来实现:就能很好的处理这个问题。
实现tabbarcongtroller的代理:
这是在模拟器下 自定义的代码:
shuaxinviewcontroller 就是第一个vc ;
nextviewcontroller 就是第二个vc;
gotoNextviewcontroller就是挑战判断;
关键是这句代码:
[tabBarController setSelectedViewController:viewController];
你大概一下子就醒悟了.....
//另外模拟器和真机的实际,稍稍有些不同,请自己调试;
-(bool)tabbarviewcontrolelr:(uitabbarviewcontrolelr *)tabbarcontroller shouldSelectViewcontroler:(uiviewcontroller)viewcontrolelr{
if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *nav =(UINavigationController *)viewController;
if (nav.viewControllers.count ==1) {
[(ShuaXinViewController *)(nav.viewControllers[0]) gotoNextViewController:nil];
[tabBarController setSelectedViewController:viewController];
return NO;
}else{
if (nav.viewControllers.count ==2) {
if ([nav.topViewController isKindOfClass:[nextViewController class]]) {
[tabBarController setSelectedViewController:viewController];
return NO;
}
}
}
}
return YES;
}
PS: 手敲的。。。不要在意细节,拼写,符号,请忽略
相关文章推荐
- iOS自定义TabBar使用popToRootViewControllerAnimated重叠问题解决
- UITabBarController作为根视图控制器的时候出现的问题,popToRootViewController的时候出现两个TabBar
- iOS开发-自定义TabBar使用popToRootViewControllerAnimated重叠问题解决
- 自定义UITabBar 在 popToViewController 或popToRootViewController后UITabBarItem出现重叠
- iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 的解决办法
- 给系统的UITabbarViewController 的tabBarItem 添加图片的问题
- iOS 视图在调用popToRootViewControllerAnimated:时uitabBar出现叠加
- cocos2d-x 2.1.1 在ios 下获取 rootviewcontroller 的问题
- IOS研究之UITabBarController隐藏tabBar以及addChildViewController
- iOS自定义tabbar后popToRootViewContriller和poptoviewcont
- iOS开发注销操作后更改rootViewController的问题
- 在ios 下获取 rootviewcontroller 的版本不同的问题
- iOS开发- UITabBarController的TabBar、TabBarItem背景颜色设置
- IOS 下获取 rootviewcontroller 的版本不同的问题解决办法
- [iOS 导航与TabBar混合] UINavigationCon+UITabBarViewController 混合使用
- iOS UITabBarController底部tabbar的item间距设置
- (原) 定制使UITabBarController的tabbar选中tabbaritem时不高亮以及换背景色(支持iPad旋转)
- iOS didFinishLaunchingWithOptions方法里获取storyBoard的rootViewController
- 猫猫学iOS 之控制器view显示中view的父子关系及controller的父子关系_解决屏幕旋转不能传递事件问题
- iOS开发——纯代码界面(UITabBarController,UINavigationController,UIImageView)