如题
遇到这样一个需求 我这边是从登陆界面(无导航栏)压栈到其它界面(登录之后无tabbar的主页、登录界面点击注册的界面等) 压栈后的界面有导航栏 说白了就登录界面无导航栏其它界面都得有
代码如下
首先Appdelegate中代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self monitoringNetwork]; ViewController *v = [[ViewController alloc]init]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:v]; self.window.rootViewController = nav; return YES; }
然后ViewController中代码
- (void)viewDidLoad {
[super viewDidLoad]; self.navigationController.delegate = self; self.navigationController.interactivePopGestureRecognizer.delegate = self; self.edgesForExtendedLayout = UIRectEdgeNone; self.view.backgroundColor = [UIColor whiteColor]; [self initUI];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([viewController isKindOfClass:[self class]]) {
[ navigationController setNavigationBarHidden:YES animated:YES]; }else { [navigationController setNavigationBarHidden:NO animated:YES];
}
}
这个是登陆界面push方法
#pragma mark 点击确定进入选择服务器地址界面
- (void)sureAction{
UIBarButtonItem *backIetm = [[UIBarButtonItem alloc] init]; backIetm.title = @"xxxx"; self.navigationItem.backBarButtonItem = backIetm; SelectSiteController *s = [[SelectSiteController alloc]init]; [self.navigationController pushViewController:s animated:YES];
}
注意 要遵循UINavigationControllerDelegate,UIGestureRecognizerDelegate这两个代理 其中
self.navigationController.interactivePopGestureRecognizer.delegate = self;
该方法 是为了防止登陆界面添加了手势动作 返回时手势失效(我遇到了这个情况,这句代码就好了
网友评论