0

I am having a problem with calling reloadData. I have 2 classes and I cannot update my table.

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;...`

and: myFirstViewController.m:

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

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

}

Why doesn't this allow me to update my table?

Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
sliwek
  • 3
  • 2

2 Answers2

0

reloadData is not getting called as the viewC's view is not loaded in the memory simply by [[ViewController alloc]init];

Due to which the tableView is not getting initialized and hence the reloadData is not getting called for tableView.

you need to call this line once your viewC's view is atleast once presented on screen.

Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41
0

You need to create a property for tableview in rootcolntrollerview.h (like below) and synthesize it in rootcolntrollerview.m (you can use IBOutlet if you are creting tableview through xib. else you can remove it. )

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

then you can reload data in myfirstviewController.m like below:

[viewC.tableview_rootview reloadData];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281