UINavigationController和UINavigationControllerDelegate

來源:互聯網
上載者:User

1. UINavigationControllerDelegate協議

a. 設定代理類 nav.delegate = self;

b. 實現協議

@protocol UINavigationControllerDelegate <NSObject>@optional// Called when the navigation controller shows a new top view controller via a push, // pop or setting of the view controller stack./*Sent to the receiver just before the navigation controller displays a view *controller’s view and navigation item properties.*/- (void)navigationController:(UINavigationController *)navigationController       willShowViewController:(UIViewController *)viewController                     animated:(BOOL)animated;/*Sent to the receiver just after the navigation controller displays a view *controller’s view and navigation item properties.*/- (void)navigationController:(UINavigationController *)navigationController        didShowViewController:(UIViewController *)viewController                     animated:(BOOL)animated;@end

2. UINavigationController

NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController /* Use this initializer to make the navigation controller use your custom bar class.    Passing nil for navigationBarClass will get you UINavigationBar, nil for toolbarClass gets UIToolbar.   The arguments must otherwise be subclasses of the respective UIKit classes. */- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass NS_AVAILABLE_IOS(5_0);- (id)initWithRootViewController:(UIViewController *)rootViewController; // Convenience method pushes the root view controller without animation.- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.- (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.@property(nonatomic,readonly,retain) UIViewController *topViewController; // The top view controller on the stack.@property(nonatomic,readonly,retain) UIViewController *visibleViewController; // Return modal view controller if it exists. Otherwise the top view controller.@property(nonatomic,copy) NSArray *viewControllers; // The current view controller stack.- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.@property(nonatomic,getter=isNavigationBarHidden) BOOL navigationBarHidden;- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated; // Hide or show the navigation bar. If animated, it will transition vertically using UINavigationControllerHideShowBarDuration.@property(nonatomic,readonly) UINavigationBar *navigationBar; // The navigation bar managed by the controller. Pushing, popping or setting navigation items on a managed navigation bar is not supported.@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden NS_AVAILABLE_IOS(3_0); // Defaults to YES, i.e. hidden.- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); // Hide or show the toolbar at the bottom of the screen. If animated, it will transition vertically using UINavigationControllerHideShowBarDuration.@property(nonatomic,readonly) UIToolbar *toolbar NS_AVAILABLE_IOS(3_0); // For use when presenting an action sheet.@property(nonatomic, assign) id<UINavigationControllerDelegate> delegate;@end

3. 建立UINavigationController

    UINavigationController *aNav = [[UINavigationController alloc] init];    //然後添加一個視圖進去,否則導覽列也沒有意義的     UIViewController *aViewCtrl = [[UIView alloc] initWithNibName: (*xib檔案名稱*)];    [aNav pushViewController:aViewCtrl animated:NO];//導覽列的第一個視圖不要動畫化

或者

    BIDFirstLevelController *first = [[BIDFirstLevelController alloc] initWithStyle: UITableViewStylePlain];    self.navController = [[TestNavgation alloc] initWithRootViewController: first];

4. 其他常用方法和屬性:

本地視圖.navigationItem.leftBarButtonItem //左側邊欄項目本地視圖.

本地視圖.navigationItem.rightBarButtonItem //右側邊欄項目本地視圖.

本地視圖.navigationItem.backBarButtonItem //後退欄項目本地視圖.

本地視圖.navigationItem.hidesBackButton //隱藏後退按鈕(YES or NO)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.