沒有導航欄進行push(壓棧)
阿新 • • 發佈:2019-02-10
如題
遇到這樣一個需求 我這邊是從登陸介面(無導航欄)壓棧到其它介面 壓棧後的介面有導航欄
程式碼如下
首先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;
該方法 是為了防止登陸介面添加了手勢動作 返回時手勢失效(我遇到了這個情況,這句程式碼就好了)