[英]Error presenting ViewController
嘗試執行此行時,位於單獨的函數中:
[self presentViewController:selectVC_ animated:YES completion:nil];
我收到此錯誤:
*由於未捕獲的異常“ NSInvalidArgumentException”而終止應用程序,原因:“ * -[__ NSArrayM insertObject:atIndex:]:對象不能為零”
我的聲明和實例化位於同一文件中
@class typesel_vc;
@interface
@property(nonatomic,strong)typesel_vc *selectVC;
@implementation
@synthesize selectVC=selectVC_;
-(void)viewDidAppear:(BOOL)animated{
selectVC_=[[typesel_vc alloc]init];
}
關於如何處理此錯誤有什么想法?
編輯:
將分配位置放在我調用presentViewController的實際行之前
selectVC_=[[typesel_vc alloc]init];
[self presentViewController:selectVC_ animated:YES completion:nil];
首先,按照慣例,類名稱應以大寫字母開頭。
其次,初始化要在以后加載控制器的視圖時呈現的模式視圖控制器是沒有意義的。 您應該在展示之前進行此操作。
第三,根據您發布的代碼無法確定錯誤。 使用日志語句和斷點單步執行代碼,以查看nil對象出現的位置。
我可以通過修改以下代碼行來解決此問題:
selectVC_=[[typesel_vc alloc]init];
[self presentViewController:selectVC_ animated:YES completion:nil];
至:
selectVC_=[self.storyboard instantiateViewControllerWithIdentifier:@"typesel_vc"];
[self presentViewController:selectVC_ animated:YES completion:nil];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.