我遇到这个代码的一个奇怪的问题。从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 :) –