简体   繁体   中英

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.

也许您需要设置UITableView的委托和数据源?

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];

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