UINavigationController的使用步驟:
1 初始化UINavigationController
2 設置UIWindow的rootViewController爲UINavigationController
3 根據具體情況,通過push方法添加對應個數的子控制器
UINavigationController以棧的形式保存子控制器
@property(nonatomic,copy) NSArray *viewControllers;
@property(nonatomic,readonly) NSArray *childViewControllers;
使用push方法能將某個控制器壓入棧
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
使用pop方法可以移除控制器
將棧頂的控制器移除
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
回到指定的子控制器
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
回到根控制器(棧底控制器)
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
如何修改導航欄的內容
導航欄的內容由棧頂控制器的navigationItem屬性決定
左上角的返回按鈕
@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem;
中間的標題視圖
@property(nonatomic,retain) UIView *titleView;
中間的標題文字
@property(nonatomic,copy) NSString *title;
左上角的視圖
@property(nonatomic,retain) UIBarButtonItem *leftBarButtonItem;
UIBarButtonItem *rightBarButtonItem 右上角的視圖
@property(nonatomic,retain) UIBarButtonItem *rightBarButtonItem;