Reputation: 75
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.
Upvotes: 0
Views: 120
Reputation: 2369
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];
Upvotes: 1