1. 程式人生 > >UINavigationController(導航控制器)及跳轉頁面的方法

UINavigationController(導航控制器)及跳轉頁面的方法

[self.navigationController pushViewController:_registVC animated:YES];

一.UINavigationController(導航控制器)

UINavigationController可以控制多個UIViewController

1.初始化一個UINavigationController

<span style="font-size:14px;">self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    
    LoginViewController *loginVC = [[LoginViewController alloc]init];
    
    UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    
    self.window.rootViewController = navigationVC;</span>

2.新增UINavigation

//UIBarButtonItem繼承於UIBarItem
    
    //1.初始化一個UIBarButtonItem
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc]initWithTitle:@"註冊" style:UIBarButtonItemStyleDone target:self action:@selector(btnItemAction:)];
    
    /*
    //2.title:修改UIBarButtonItem的名稱
    btnItem.title = @"adklfj";
    
    //3.enabled:標識UIBarButtonItem是否為可編輯,其預設值為YES.
    btnItem.enabled = NO;
    
    //4.image:給UIBarButtonItem設定一張圖片
    btnItem.image = [[UIImage imageNamed:@"zx"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    */
    
    
    //5.修改UINavigationController的title.
    self.navigationItem.title = @"登陸";
    
    //6.navigationBarHidden:隱藏navigationController的導航欄,預設值是NO
    self.navigationController.navigationBarHidden = NO;
    
    //7.//navigationBar:設定navigationBar.<span style="color:#FF0000;">translucent</span>(透明度)的值為NO,其預設值是YES;設定navigationBar的值為NO後,檢視的(0,0)點就是在navigationBar的左下角.
    self.navigationController.navigationBar.translucent = NO;
    

二.跳轉頁面的方法

1.從前往後跳轉頁面

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; 
// Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
例如:
[self.navigationController pushViewController:_registVC animated:YES];

2.從後往前跳轉頁面

//這個方法是返回前一個介面
- (UIViewController *)popViewControllerAnimated:(BOOL)animated; 
// Returns the popped controller.

//這個方法是返回到在同一條鏈路上的任意一個介面
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; 
// Pops view controllers until the one specified is on top. Returns the popped controllers.

//這個方法是返回到根檢視
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated; 
// Pops until there's only a single view controller left on the stack. Returns the popped controllers.