在這裏我要說一下,ios開發的知識點都偏於基礎,我只記錄了一些基礎的知識點,並進行了擴展,適合入門的朋友:
【IOS初學者】UITableView與自定義UITableViewCell
【IOS初學者】bundle知識點總結
【IOS初學者】數組與字典javascript
UINavigationController是IOS編程中比較經常使用的一種viewcontroller,在介紹它的功能以前,咱們先對比一下是否使用UINavigationController,在界面上有什麼異同:java
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:[MainViewController new]];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
//使用navigationController
// self.window.rootViewController = navigationController;
//不使用navigationController
self.window.rootViewController = [EmptyViewController new];複製代碼
根據以上代碼,咱們能夠看到以下的運行結果:ios
根據上圖對比可知,使用navigationController比普通的viewcontroller多了上面一層導航條,能夠更方便的控制界面的跳轉。編程
介紹UINavigationController view層級,咱們先從一張圖開始:數組
UINavigationController也是一個ViewController,並不單單是一個導航條,它是在普通的ViewController基礎上增長了新的功能。根據上面的圖,咱們進行逐步的分析。less
咱們都知道navigationItem是UIViewController的一個屬性,這個屬性是爲UINavigationController服務的。
查看源碼,UINavigationItem中有兩個比較經常使用的item:post
// Some navigation items want to display a custom left or right item when they're on top of the stack.
// A custom left item replaces the regular back button unless you set leftItemsSupplementBackButton to YES
@property(nullable, nonatomic,strong) UIBarButtonItem *leftBarButtonItem;
@property(nullable, nonatomic,strong) UIBarButtonItem *rightBarButtonItem;複製代碼
也就是導航欄上的左右button,他們都是navigationItem中的一個組件,咱們能夠直接設置,例如:ui
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"Root"
style:UIBarButtonSystemItemAction
target:self
action:@selector(butClick)];
self.navigationItem.rightBarButtonItem = rightItem;
self.navigationItem.title = @"Hello, im the title";複製代碼
運行結果以下:atom
UINavigationItem繼承自NSObject,包含了當前頁面導航欄上須要顯示的所有信息:title,prompt,titleView,leftBarButtonItem,rightBarButtonItem,backBarButonItemspa
UINavigationBar繼承自UIView,看一下他的屬性可知,他主要是對UINavigationItem進行管理的。
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
// Pushing a navigation item displays the item's title in the center of the navigation bar.
// The previous top navigation item (if it exists) is displayed as a "back" button on the left.
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated;
- (nullable UINavigationItem *)popNavigationItemAnimated:(BOOL)animated; // Returns the item that was popped.
@property(nullable, nonatomic,readonly,strong) UINavigationItem *topItem;
@property(nullable, nonatomic,readonly,strong) UINavigationItem *backItem;
@property(nullable,nonatomic,copy) NSArray<UINavigationItem *> *items;
- (void)setItems:(nullable NSArray<UINavigationItem *> *)items animated:(BOOL)animated;
........複製代碼