iOS 实现点击tabbar跳转登录页面
2018-01-08 09:57
1636 查看
在APP的设计中常常有需要点击tabbar直接进行跳转登录的操作。下面说一下需要怎么来实现这个操作。
代码。
(BOOL)tabBarController:(UITabBarController )tabBarController shouldSelectViewController:(UIViewController )viewController {
[[self cyl_tabBarController] updateSelectionStatusIfNeededForTabBarController:tabBarController shouldSelectViewController:viewController];
NSInteger selectedIndex;
if ([viewController.tabBarItem.title isEqualToString:@”我的”]) {
if ([UserManager isLogin]) {
return YES;
}else{
loginPhoneViewController *login = [[loginPhoneViewController alloc]init];
login.className = @”tabbar”;
selectedIndex = 2;
login.selectedIndex = selectedIndex;
[tabBarController.selectedViewController.rt_navigationController presentViewController:login animated:YES completion:^{
}];
[[[NSNotificationCenter defaultCenter]rac_addObserverForName:@”loginNotice” object:nil]subscribeNext:^(NSNotification * _Nullable x) {
tabBarController.selectedIndex = 2;
}];
}
return NO;
}else{
return YES;
}
}
1.首先是要再tabbar的代理shouldselect代理中,如果选择didselect的代理则会出现点击tabbar会先展示tabbar所对应的子试图再跳转的情况。
2.判断你需要在哪个tabbar中进行登录或者其他的跳转,通过tabbaritem.title来进行判断,在这里tabbar名字为”我的”;
3.然后进行条件判断 usermanager是个人封装的登录信息管理类。如果[UserManager isLogin] 则返回YES ,及表示如果登录了直接跳转到对应的子试图。如果返回NO 则要跳转登录,这里登录为LoginViewController,操作中的login.className是不属于这里的一个操作,个人用于别的地方。
4.定义了一个selectIndex的常量用于记录tabbar的index; 这里是第二个按钮为“我的”。(用于登录之后)
5.在登录界面定义selectedIndex,将当前选择的index告诉登录页面。(用于登录之后使用)
6.实现跳转,这里使用的方式为模态方式。
7.需要实现直接跳转的需要return YES,需要跳转登录的 return NO;(如上代码)
8.同时通过rac添加了一个名为”loginNotice”的通知监听。用于登录之后将tabbar的index不再绑定为登录页面。(重置)
9.在登录页面代码如下
[[NSNotificationCenter defaultCenter]postNotificationName:@”loginNotice” object:nil];
在登录成功中发送这个通知。
即完成以上操作 即可完成点击tabbar直接跳转登录的操作。
代码。
(BOOL)tabBarController:(UITabBarController )tabBarController shouldSelectViewController:(UIViewController )viewController {
[[self cyl_tabBarController] updateSelectionStatusIfNeededForTabBarController:tabBarController shouldSelectViewController:viewController];
NSInteger selectedIndex;
if ([viewController.tabBarItem.title isEqualToString:@”我的”]) {
if ([UserManager isLogin]) {
return YES;
}else{
loginPhoneViewController *login = [[loginPhoneViewController alloc]init];
login.className = @”tabbar”;
selectedIndex = 2;
login.selectedIndex = selectedIndex;
[tabBarController.selectedViewController.rt_navigationController presentViewController:login animated:YES completion:^{
}];
[[[NSNotificationCenter defaultCenter]rac_addObserverForName:@”loginNotice” object:nil]subscribeNext:^(NSNotification * _Nullable x) {
tabBarController.selectedIndex = 2;
}];
}
return NO;
}else{
return YES;
}
}
1.首先是要再tabbar的代理shouldselect代理中,如果选择didselect的代理则会出现点击tabbar会先展示tabbar所对应的子试图再跳转的情况。
2.判断你需要在哪个tabbar中进行登录或者其他的跳转,通过tabbaritem.title来进行判断,在这里tabbar名字为”我的”;
3.然后进行条件判断 usermanager是个人封装的登录信息管理类。如果[UserManager isLogin] 则返回YES ,及表示如果登录了直接跳转到对应的子试图。如果返回NO 则要跳转登录,这里登录为LoginViewController,操作中的login.className是不属于这里的一个操作,个人用于别的地方。
4.定义了一个selectIndex的常量用于记录tabbar的index; 这里是第二个按钮为“我的”。(用于登录之后)
5.在登录界面定义selectedIndex,将当前选择的index告诉登录页面。(用于登录之后使用)
6.实现跳转,这里使用的方式为模态方式。
7.需要实现直接跳转的需要return YES,需要跳转登录的 return NO;(如上代码)
8.同时通过rac添加了一个名为”loginNotice”的通知监听。用于登录之后将tabbar的index不再绑定为登录页面。(重置)
9.在登录页面代码如下
[[NSNotificationCenter defaultCenter]postNotificationName:@”loginNotice” object:nil];
在登录成功中发送这个通知。
即完成以上操作 即可完成点击tabbar直接跳转登录的操作。
相关文章推荐
- iOS -- 点击button实现tabbar视图控制器跳转
- iOS实现点击按钮,跳转到与mian.storyboard 中与ViewController 关联的页面
- iOS实现在webview页面内点击链接,跳转指定App
- iOS tabBar 相应的代理,用来实现当没有登录的时候,就点击无效。
- iOS引导登录、登录引导、login(点击某个功能按钮需要登录并且登录完成后自动跳转到要去的功能实现方法)
- iOS 开发之 点击tabbarItem添加是否跳转登录页面判断
- iOS实现在webview页面内点击链接,跳转指定App
- iOS 开发之 点击tabbarItem添加是否跳转登录页面判断
- iOS 开发之 点击tabbarItem添加是否跳转登录页面判断
- (iOS开发)点击tabbar中的按钮显示首页,再如何跳转页面
- iOS tabbar和navigation组合,点击item两次,会pop到上一个页面,解决不让控制器跳转的方法
- iOS 点击一个页面上的按钮跳转到tabBar的另一个页面
- yii实现注册成功即登录,不需跳转登录页面登录
- 在jquery mobile中页面跳转的时候,实现登录检查
- 重写 ajax 实现 session 超时跳转到登录页面实例代码
- servlet中实现提示登录成功后跳转到某一页面
- 个人笔记 js 14 js实现点击单元格行跳转链接到指定页面
- 在WebBrowser控件中实现自动登录并跳转到指定页面
- 怎么实现登录之后跳转到登录之前的页面?SpringMVC+Freemarker
- ios开发:跳转到根视图并跳转到第一个tabbar第一个页面