Morocco5 Morocco5 - 1 year ago 89
Objective-C Question

How to access programmatically a tableview added with storyboard

I added a tableview to my viewcontroller using the storyboard. What is actually happening behind the scenes? If a UITableview object gets created how can I access this object programmatically? What is the name of the instance? Is it a property of my viewcontroller object?

More specifically, what I need to do is force my tableview to refresh (from inside of my viewcontroller). I read in other posts that I should be able to do something like this [self.tableview reloadData]. I can't do this because my viewcontroller does not have a property called "tableview" (or anything similar)

Answer Source

Control + click and drag your tableView into your header file to create an IBOutlet

enter image description here

Set the delegate and data source by control click and drag from your table view to your view controller - make sure both dots are seen. Now

enter image description here

In the interface .h file add the delegate and datasource as such:

@interface HomeTableViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>

Now your view controller should have access to the methods needed to use [self.tableView reloadData]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download