简体   繁体   中英

reloadData() and setting IBOutlets without Interface Builder

I have created a UITableView inside my UIViewController programmatically using this guide on the Speak Objectively Blog .

However I now have the problem that .reloadData() isn't refreshing the view. However if I drag or move inside the UITableView the data appears correctly.

This answer suggests that I haven't set up the outlet . To my understanding IBOutlets are for connecting elements in the Interface Builder to the code. Please correct me if my understanding here is wrong.

How do I set an outlet if I created the UITableView programmatically?

The guide creates a UITableViewController. It has already an instance of UITableView on it, and it is the one you see in screen. There's no need of creating outlets, so that answer is not actually the answer to your problem (but might be somehow related)

What I can imagine is that you are sending the message somewhere else.

As you can see in the Table View Controller Class Reference , you can get your table view by self.tableView (or just tableView in swift)

So make sure you are sending the message to self.tableView.reloadData()

If it doesn't work, sending part of your code will help us to see better than to imagine where could be the problem ;)

If self.tableView.reloadData() doesn't work on its own, use:

dispatch_async(dispatch_get_main_queue(), {self.tableView.reloadData()})

or

dispatch_async(dispatch_get_main_queue()) {self.tableView.reloadData()}

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