我遇到這個代碼的一個奇怪的問題。從NSMutableArray填充UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
if (accounts != nil) {
NSLog(@"Cell: %@", indexPath.row);
cell.textLabel.text = [self.accounts objectAtIndex: indexPath.row];
}
else
{
NSLog(@"No cells!");
[cell.textLabel setText:@"No Accounts"];
}
return cell;
}
我的表視圖填充就好了,除了所有的行包含在我的NSMutableArray
,accounts
的第一個項目。我正在記錄indexPath.row
的值,並且無論數組中有多少個值,它都會保持爲(null)。我在這裏做錯了什麼?
我剛纔說如果你是cellForRowAtIndexPath只會被調用一次,請檢查你的numberOfRows :) –