![](/img/trans.png)
[英]Instantiate ViewController with identifier causes a crash using storyboard and a xib
[英]instantiate ViewController With storyboard Identifier in IOS
我正在使用iOS應用程序,該應用程序允許用戶使用其Facebook帳戶登錄。 我們登錄的用戶我想推送充滿用戶數據的配置文件ViewController; 很抱歉這么長的預備期 。
問題是當我使用instantiateViewControllerWithIdentifier
方法啟動配置文件視圖控制器時。 它的出口部分都為零
這是我面臨問題的代碼
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
profileViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CGProfileViewController"];
profileViewController.fbProfilePictureView.profileID=user.objectID;
profileViewController.nameLabel.text=user.name;
profileViewController.locationLabel.text=user.location.location.city;
// [self presentViewController:profileViewController animated:YES completion:nil]
}
我的代碼有什么問題嗎? 我該怎么辦 ? 預先感謝
這里的問題是您引用的出口尚未創建。 我會嘗試將User模型添加為視圖控制器的屬性(或為此使用某種中間控制器),在上面的函數中設置user屬性,然后在viewDidAppear
使用User模型適當地設置所有控件的文本。
如果在viewDidAppear
函數上執行此操作,則可以確定所有視圖都已實例化。 畢竟,這也是更好的設計; 為什么您的LoginViewController類需要了解profileViewController
的內部信息? 以這種方式封裝邏輯將減少問題的產生。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.