UINavigationController : UIViewController
1.創建UINavigationController對象
UINavigationController *navCV = [[UINavigationController alloc]initWithRootViewController:mainVC];
通常和
self.window.rootViewController = navCV;
連用
2.- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
推出第二個頁面
eg:[self.navigationController pushViewController:secondVC animated:YES];
3.- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
返回上一視圖
eg:[self.navigationController popViewControllerAnimated:YES];
4.- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
返回指定視圖
eg:獲得viewController的棧
UIViewController *viewC = [self.navigationController.viewControllers objectAtIndex:0];
[self.navigationController popToViewController:viewC animated:YES];
5.- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
返回根視圖
eg:[self.navigationController popToRootViewControllerAnimated:YES];
UINavigationItem : NSObject <NSCoding>
每個頁面要顯示在導航欄上的內容(標題,兩邊按鈕信息)
1.rightBarButtonItem
創建導航欄右邊按鈕
參數1 選擇一個系統提供的圖標信息
eg:self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(button:)]autorelease];
2.leftBarButtonItem
創建導航欄左邊按鈕
eg:self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-yinle.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button:)]autorelease];
3.hidesBackButton
隱藏返回按鈕
eg:self.navigationItem.hidesBackButton = YES;
4.titleView
標題相關設置
eg:self.navigationItem.titleView = [[[UISegmentedControl alloc]initWithItems:@[@"111",@"222"]]autorelease];
UINavigationbar
1.translucent
是否透明
eg:self.navigationController.navigationBar.translucent = YES;
2.barTintColor
bar的顏色eg:self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
3.setNavigationBarHidden
隱藏bar
e.g.:[self.navigationController setNavigationBarHidden:NO];
4.automaticallyAdjustsScrollViewInsets
取消掉scrollView的系統設置的UIEdgeInsets
e.g.:elf.automaticallyAdjustsScrollViewInsets = YES;
(當頁面出現不可預知問題時可以嘗試使用這個開關)
5.setBackgroundImage
設置bar背景圖片
eg:[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"2.png"] forBarMetrics:UIBarMetricsDefault];