我想在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;
}