Life is Really Short, Have Your Life!!

ござ先輩の主に技術的なメモ

ViewDidLoadが複数回呼ばれて気持ち悪い

UIViewControllerのプロパティとしてUITableViewをコードからallocしているんですが、なぜかこいつだけviewDidLoadが複数回呼ばれていました。

で、ぐぐったらやっぱり同じ悩みを持っている人がいました。

Set the view property of the view controller to a valid view.

iphone - Multiple calls to viewDidLoad/loadView - Stack Overflow

なん・・・・だと・・・!

- (void)viewDidLoad {
    //cartTableはUITableViewです
    cartTable = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen]applicationFrame]];
    cartTable.delegate = self;
    cartTable.dataSource = self;
    //こいつを追加した
    self.view = cartTable;
    NSLog(@"called viewDidLoad");
    [super viewDidLoad];
}

これで1度しか呼ばれなくなりました。いやー気持ち悪かったのでスッキリ。