Я пытаюсь отобразить некоторые массивы в UITableViewController. У меня есть пользовательская ячейка с NIB. Проблема, с которой я сталкиваюсь, - это то, что мои строки таблицы пытаются заполнить, прежде чем мои массивы будут загружены в мой ViewDidLoad
. Установка точек прерывания показывают, что мои строки таблицы создаются и затем непосредственно после моих массивов приведены значения (которые установлены в моем ViewDidLoad
.tableView cellForRowAtIndexPath: выполняется перед ViewDidLoad?
Может кто-нибудь сказать мне, почему метод tableView
работает до ViewDidLoad
? Что мне нужно сделать сделать, чтобы мои массивы загружены до строки таблицы заполняются
Вот мой ViewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"go");
PFQuery *getCartQuery = [PFQuery queryWithClassName:@"chwCart"];
[getCartQuery whereKey:@"userId" equalTo:[PFUser currentUser].objectId];
[getCartQuery whereKey:@"status" equalTo:@"open"];
[getCartQuery getFirstObjectInBackgroundWithBlock:^(PFObject *currentCartObject, NSError *error) {
// NSLog([currentCartObject objectId]);
currentCart = [currentCartObject objectForKey:@"cartContents"];
dictFoodId = [currentCart valueForKey:@"foodId"];
dictQty = [currentCart valueForKey:@"qty"];
}];
NSLog(@"Should be loaded");
[self.tableView registerNib:[UINib nibWithNibName:@"foodCell" bundle:nil] forCellReuseIdentifier:@"foodCell"];
}
Вот мой tableView cellForRowAtIndexPath:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"foodCell";
foodCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[foodCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.foodTitle.text = [dictQty objectAtIndex:indexPath.row];
return cell;
}