您的位置:首页 > 移动开发 > IOS开发

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直接跳转登录的操作。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐