Keep getting nil from dequeueReusableCellWithIdentifier?

后端 未结 5 1268
清酒与你
清酒与你 2020-12-11 05:20

I\'ve created a prototype cell with identifier \"mainViewTableCell\" in storyboard file and connected the main table view with a custom controller class named \"NTTableViewC

5条回答
  •  爱一瞬间的悲伤
    2020-12-11 05:48

    After reading @Firoze's answer I fixed my problem that had been haunting me for days.. and found another solution. I know the question has already been answered but this may help someone out.

    In my case I had done some refactoring (extracted a new TableViewController), and afterwards I was getting nil cells returned from dequeueReusableCellWithIdentifier.

    The fix for me was to do this instead of calling alloc/init on my ViewController in didSelectRowAtIndexPath:

    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                  bundle:nil];
    
    MyTableViewController* controller = [sb instantiateViewControllerWithIdentifier:
                                        @"MyTableViewController"];
    

    (Then I call [self.navigationController pushViewController:controller animated:YES]; - not the cleanest way perhaps but it works)

提交回复
热议问题