0

我打电话有问题reloadData。我有 2 节课,我无法更新我的表。

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

}

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

4

2 回答 2

0

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

@property (retain, nonatomic) IBOutlet UITableView *tableview_rootview;

然后你可以myfirstviewController.m像下面这样重新加载数据:

[viewC.tableview_rootview reloadData];
于 2012-08-23T09:41:35.210 回答
0

reloadData没有被调用,因为 viewC 的视图没有被简单地加载到内存[[ViewController alloc]init];

中,因此 tableView 没有被初始化,因此没有为 tableView 调用 reloadData。

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

于 2012-08-23T09:34:12.397 回答