Passing data with delegate but still nil why?

3764 views ios
4

I made 2 viewcontrollers and implemented on tabbar controller. I passed some data from A vc to B vc with using delegate. When I checked the log it showed me correct value. But when I moved to B vc the value I passed was nil. (the value is for tableview.) Here is my code.

    in A vc

    -(void)passData {

        NSMutableDictionary *infoDic = [[NSMutableDictionary alloc] init];
        [infoDic setObject:url forKey:@"file_url"];
        [downloadArr addObject:fileInfoDic];

        [Bvc getDataFromA:downloadArr];
        [Bvc reloadTableView];        
    }

    in B vc

  -(void)getDataFromA:(NSMutableArray *) downloadArr{
        self.downloadArr = [downloadArr mutableCopy];
        NSLog(@"my download list%@", self.downloadArr); // This time was ok.
}
    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];

        NSLog(@"Array status %@", self.downloadArr);//This time it showed me nil
        [self.tableView reloadData];
    }

answered question

1 Answer

1

To have the array printed inside viewWillAppear without nil

NSLog(@"Array status %@", self.downloadArr);//This time it showed me nil

you need to give it a value before you show bVC from aVC , whatever you use present/segue/push , also don't forget to declare it as strong

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories