Ios UITableView重新加载数据在另一个类中不起作用

Ios UITableView重新加载数据在另一个类中不起作用,ios,xcode,uitableview,reloaddata,Ios,Xcode,Uitableview,Reloaddata,我在调用reloadData时遇到问题。我有2个类,无法更新我的表 myrootViewController.m: [self presentModalViewController:firstV animated:NO]; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyCellIdent

我在调用
reloadData
时遇到问题。我有2个类,无法更新我的表

my
rootViewController.m

[self presentModalViewController:firstV animated:NO];

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *MyCellIdentifier = @"MyCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyCellIdentifier];
         cell.selectionStyle = UITableViewCellSelectionStyleGray;
        //cell.textLabel.text = @"dupa";
        //cell.textLabel.font = [ UIFont fontWithName: @"Arial" size: 50.0 ];
            }

    NSLog(@"xxx ===== %@",firstVC.xxx);

    UIImageView *imgView = [[UIImageView alloc]init];
    UILabel *rankLabel = [[UILabel alloc]init];
    UILabel *rankDetail = [[UILabel alloc]init];
    UILabel *cyclesLabel = [[UILabel alloc]init];
    UILabel *cyclesDetail = [[UILabel alloc]init];
    UILabel *approxLabel = [[UILabel alloc]init];
    UILabel *approxDetail = [[UILabel alloc]init];
    UILabel *leftP = [[UILabel alloc]init];
    UILabel *rightP = [[UILabel alloc]init];
    UILabel *leftQ = [[UILabel alloc]init];
    UILabel *rightQ = [[UILabel alloc]init];
    UILabel *timeLabel = [[UILabel alloc]init];
    UILabel *timeDetail = [[UILabel alloc]init];
    UILabel *freeProductLabel = [[UILabel alloc]init];
    UILabel *freeDetailLabel = [[UILabel alloc]init];

    NSString *approxString;
    NSString *leftPeqsString;
    NSString *rightPeqsString;
    NSString *leftQString;
    NSString *rightQString;


    switch (indexPath.row) {
        case 0:
            imgView.frame = CGRectMake(10.0, 15.0, 80.0, 80.0);
            imgView.image = [UIImage imageNamed:@"Ambassador@2x.jpeg"];
            imgView.layer.cornerRadius = 40;
            imgView.layer.masksToBounds = YES;
            //imgView.contentMode = UIViewContentModeScaleAspectFit;
            //cell.imageView.image = imgView.image;
            [cell.contentView addSubview:imgView];
            rankLabel.frame = CGRectMake(110.0, 45.0, 200.0, 50.0);
            rankLabel.text = firstVC.xxx;
            rankLabel.textColor = [UIColor orangeColor];
            rankLabel.font = [UIFont boldSystemFontOfSize:28];
            [cell.contentView addSubview:rankLabel];
            rankDetail.text = @"Your current rank:";
            rankDetail.frame = CGRectMake(110.0, 30.0, 200.0, 30.0);
            rankDetail.font = [UIFont boldSystemFontOfSize:16];
            [cell.contentView addSubview:rankDetail];
            //cell.textLabel.font = [UIFont systemFontOfSize:20];
            //cell.textLabel.textColor = [UIColor orangeColor];
            break;...`
和:
myFirstViewController.m

- (void)date:(NSString*)data
{
    ViewController *viewC = [[ViewController alloc]init];

    xxx = rank;
    NSLog(@"FVC rank xxx ==== %@", xxx);
    [viewC.tableView reloadData];

}

为什么这不允许我更新我的表?

reloadData
没有被调用,因为viewC的视图没有通过
[[ViewController alloc]init]加载到内存中

导致tableView未初始化,因此tableView未调用重载数据


一旦viewC的视图至少在屏幕上显示一次,您就需要调用此行。

您需要在
rootcolcontrollerview.h
(如下所示)中为tableview创建一个属性,并在
rootcolcontrollerview.m
(如果要通过
xib
创建tableview,则可以使用
IBOutlet
。否则可以将其删除。)

然后可以在
myfirstviewController.m
中重新加载数据,如下所示:

[viewC.tableview_rootview reloadData];

我强烈建议您重新考虑在
cellforrowatinexpath
中分配所有这些标签。
[viewC.tableview_rootview reloadData];