Search code examples
xcodeuiviewcontrolleruitableviewreloaddata

tableView property with UIViewController (or UITableViewController)


#import <UIKit/UIKit.h>

@interface FourthViewController : UIViewController{

//@interface FourthViewController : UITableViewController{

I want to update my tableview so I trying to use [self.tableView reloadData] but i cannot even type this line of code since I'm working in a UIViewController and the tableView property is for UITableViewController's only. So I tried to be smart and just change the UIViewController to UITableViewController but instead i got this error:

 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "b4k-XH-Uhj-view-V2h-dE-ixJ" nib but didn't get a UITableView.'

Imo this is strange since a UITableViewController would work for a tableView but not the other way around, but seams like i got it all wrong, or whats happening here? more code if you ask for it =) Thanks ahead.


Solution

  • A UITableViewController is really just a UIViewController that contains an outlet to a UITableView and implements the two tableview delegates: UITableViewDelegate and UITableViewDataSource.

    You may want to consider replacing the viewcontroller instance in your nib file with a UITableViewController rather than a standard UIViewController.

    Alternatively, you can manually adjust your ForthViewController instance by creating an outlet for the contained UITableView to expose the tableview as a property.

    However, if you do it this way you'll also have to manually implement the two tableview delegates UITableViewDelegate and UITableViewDataSource somewhere (probably in ForthViewController) and manually associate the UITableView with these delegates.