如有謬誤或需要補充的內容,請聯繫 [email protected]
需要注意的地方
- 如果 xib 中的空間已經和 File’s owner 建立關聯,當刪除這個控件或者刪除此控件對應的屬性時,需要首先接觸這種綁定關係,否則可能導致 crash
- 使用 storyboard 時,如果針對不同平臺(iPhone、iPad)有不同的 storyboard 入口,則需要在 plist 文件中聲明,響應的 key 爲 “Main storyboard file base name”和“Main storyboard file base name (iPad)”,value 則爲對應 storyboard 的名稱
小技巧
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender
在顯示下一個 viewController 前,這裏可以做些預處理,比如給自定義的 viewController 屬性設置初始值- 使用
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender
可以主動觸發對應的跳轉操作 - 如果用 xib 創建了一個 view 並且 view 的 File’s owner 已經設置,則在對應的 owner 中(如:這個 view 是在 view controller 中作爲屬性存在),可以通過下面的方式加載,詳見官方 demo
UINib *landscapeViewXib = [UINib nibWithNibName:@"LandscapeView" bundle:nil];
// In the LandscapeView xib the "File's Owner" has been set to
// ViewController and the landscapeView IBOutlet of the file's owner
// has been connected to the view defined within the xib. Thus upon
// instantiation, the unarchived view will be automatically connected
// to the landscapeView of self.
[landscapeViewXib instantiateWithOwner:self options:nil];