简体   繁体   中英

TableView reload data troubles

I have a function which creates a few arrays and fills them with data. I execute this function from viewDidLoad .

In the function I add [self.tableview reloadData];

I set breakpoints etc and it doesn't even go to numberOfRowsInTableView etc. Should [self.tableview reloadData] execute all the table view functions so it appears on the iPhone screen?

** UPDATE **

Firstly the function is called :

- (void)viewDidLoad
{

    [super viewDidLoad];

    ViewController *GetDeals = [[ViewController alloc] init];
    [GetDeals TopDealsRecieve:[[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"]];

    [self.tableview setDelegate:self];
    [self.tableview setDataSource:self];

    [self.tableview reloadData];

The function TopDealsRecieve gets the arrays like this :

 NSLog(@"%@", responseObject);
        allLogos = [[responseObject valueForKey:@"data"] valueForKey:@"logo"];
        allcontent = [[responseObject valueForKey:@"data"] valueForKey:@"content"];
        allpostode = [[responseObject valueForKey:@"data"] valueForKey:@"postcode"];
        NSLog(@"%lu", (unsigned long)allcontent.count);
        allname = [[responseObject valueForKey:@"data"] valueForKey:@"name"];
        alladdress = [[responseObject valueForKey:@"data"] valueForKey:@"address"];
        alladdress2 = [[responseObject valueForKey:@"data"] valueForKey:@"address2"];
        alllat = [[responseObject valueForKey:@"data"] valueForKey:@"lat"];
        alllong = [[responseObject valueForKey:@"data"] valueForKey:@"lng"];
        // refresh the table view
        [self.tableview setDelegate:self];
        [self.tableview setDataSource:self];
        [self.tableview reloadData];

and in :

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   NSLog(@"wnks %lu",(unsigned long)allcontent.count);
   return allcontent.count;

}

All the variables are available all throughout my code and they are assigned like this :

// global var

NSArray *alllocationsID;
NSArray *alllocationsCity;
NSArray *allLogos;
NSArray *allcontent;
NSArray *allpostode;
NSArray *allname;
NSArray *alladdress;
NSArray *alladdress2;
NSArray *alllat;
NSArray *alllong;

At the top of the ViewController. This did work when the GetArray function wasn't a function and it was just placed in ViewDidLoad.

You should to add these 2 lines to your method viewDidload before to execute [self.tableview reloadData]; like this

[self.tableview setDelegate:self];
[self.tableview setDataSource:self];

[self.tableview reloadData];

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