UITableViewController not loading data

前端 未结 4 1344
误落风尘
误落风尘 2020-12-22 12:36

So I have created a subclass of UITableViewController and set the delegate and datasource to itself. But still the methods like cellForRowAtIndexPath

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-22 12:54

    If you are extending the UITableViewController it already creates UITableView instance at viewDidLoad. Try to set a breakpoint there and check it in debugger console:

    po [self view]
    

    Therefore you should not create the UITableView instance by yourself at this point. If you need a custom init of the table view you should do it earlier

    EDIT

    From the documentation:

    About Table Views in iOS-Based Applications

    The easiest and recommended way to create a table view is to create a custom UITableViewController object. UITableViewController creates the table view and assigns itself as delegate and data source.

    Creating a Table View Programmatically

    If you choose not to use UITableViewController for table-view management, you must replicate what this class gives you “for free.”

    - (void)loadView // <-- NOT VIEW DID LOAD!
    {
        UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]
                                      style:UITableViewStylePlain];
        tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView reloadData];
    
        self.view = tableView;
        [tableView release];
    }
    

提交回复
热议问题