简体   繁体   中英

tableView(:cellForRowAtIndexPath:) Not Called

I know this question has been asked a million times, but I came across this problem and couldn't figure it out for the life of me, and all the previous examples only have unique code to their problem.

I have a viewcontroller, inside of which I have a tableview. I created a custom tableviewcell class and my problem: The cellforrowatindexpath, which is set up in the viewcontroller isn't even called. I've included the UITableViewDataSource and UITableViewDelegate protocols, but no results - my tableview shows up without any of the configurations (mainly populating the cells).

It's super simple, I just figured it out:

Go to the storyboard, select the tableview and ctrl-drag to the yellow box at the top of the view controller (This is a reference to the view controller itself). Then make sure to select both the delegate and datasource options (white dot to the left of the options indicates they're selected).

You can set the delegate properties in storyboards like you mention above but you can also set them in viewDidLoad using:

self.tableView.delegate = self
self.tableView.datasource = self

This will create the reference to the UITableViewDelegate and UITableViewDataSource

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM