ngoue
ngoue

Reputation: 1055

UITableView doesn't display data

I've spent the last two days pouring over stack overflow and other forums for the answer to this.

I've got a mainViewController that pushes to another viewController when a button is pushed. The new view controller has a custom UITableViewController and UITableView as a childViewController and subview. Here is the code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Create TableView
    TeamTableViewController *teamTVC = [[TeamTableViewController alloc] init];
    [self addChildViewController:teamTVC];
    teamTVC.teams = self.teams;
    teamTVC.view = [[UITableView alloc] initWithFrame:CGRectMake(212, 200, 600, 300) style:UITableViewStylePlain];
    [self.view addSubview:teamTVC.view];

}

When I do it this way, the information in the @property teams doesn't get displayed to the tableView. However, if I switch my code and just push straight to the TeamTableViewController from the mainViewController, the @property teams is correctly displayed to my UITableView.

Not sure what to do to fix it that will allow me to embed the TableView in another ViewController and still display the information.

Upvotes: 0

Views: 127

Answers (2)

ngoue
ngoue

Reputation: 1055

Turns out I needed to set my @property tableView as the embedded view.

so my code:

teamTVC.view = [[UITableView alloc] initWithFrame:CGRectMake(212, 200, 600, 300) style:UITableViewStylePlain];

should be:

teamTVC.tableView = [[UITableView alloc] initWithFrame:CGRectMake(212, 200, 600, 300) style:UITableViewStylePlain];

Upvotes: 0

ilya n.
ilya n.

Reputation: 18816

Perhaps you need to set UITableView's delegate and data source?

Upvotes: 1

Related Questions