Alan
Alan

Reputation: 9481

self.TableView not working for a TableViewController inside a ViewController?

I am making a ViewController with 2 tableviews inside it. I am structuring it like ViewController -> 2 x TableViewController classes. What I don't understand is that if I do [self.tableView reloadData] in the TableViewControllers it doesn't do anything.

If I do [tableViewA reloadData] in the ViewController it will execute the datasource methods in the TableViewController.

How do I call reloadData within the TableViewControllers?

Thanks, Alan

Edit - This is how I setup the ViewController

if(self.reviewController == nil)
{
    self.reviewController = [[ReviewerTableViewController alloc] init];
}
if(self.approverController == nil)
{
    self.approverController = [[ApproverTableViewController alloc] init];
}
[self.reviewerTableView setDataSource:reviewController];
[self.approversTableView setDataSource:approverController];

[self.reviewerTableView setDelegate:reviewController];
[self.approversTableView setDelegate:approverController];

self.reviewController.view = self.reviewController.tableView;
self.approverController.view = self.approverController.tableView;

It seems like the datasource methods run once when I initialize them, but reloadData does not work inside.

I am basically just using the datasource methods in the UITableViewControllers and I am calling a method to pull data from the net. Once I get the data, I call reloadData, but the datasource methods are not executed.

Upvotes: 0

Views: 417

Answers (4)

Echelon
Echelon

Reputation: 7922

This seems very strange: you're trying to set the child UITableViewControllers' dataSource and delegates to be some local UITableViews declared (presumably) in your master view controller. It isn't supposed to work like this - the child UITableViewControllers are already the dataSource and delegate to their own implicit table views. There's no need to wired them up to separate UITableViews.

EDIT: I am assuming your "TableViewController" classes are UITableViewControllers. If not, then what you're doing may be valid, but I'd need to see all the code, headers included.

Upvotes: 0

mashdup
mashdup

Reputation: 875

Are you calling reloadData from the rootViewController? if so, you call

[self.reviewerTableView reloadData];

Upvotes: 1

Michele Percich
Michele Percich

Reputation: 1902

Be sure the TableViewControllers' tableView properties are connected to the correct table views.

Upvotes: 1

Bob Provencher
Bob Provencher

Reputation: 450

I would create a UIVIewController that implements the UITableViewDataSource and UITableViewDelegate protocols. Create two outlets, one for each tableview and make sure to wire them up in the interface builder.

then call [tableView1 reloadData];

Upvotes: 0

Related Questions