在对table中每一个cell进行初始化时候,是下面这个函数
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCellalloc] initWithFrame:CGRectZeroreuseIdentifier:MyIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text=[[colorListobjectAtIndex:indexPath.row] objectForKey:@"titleValue"];
cell.textLabel.textColor=[[colorListobjectAtIndex:indexPath.row] objectForKey:@"colorValue"];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
这里要注意,代码只会自动生成
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
这两句,而
if (cell == nil) {
cell = [[[UITableViewCellalloc] initWithFrame:CGRectZeroreuseIdentifier:MyIdentifier] autorelease];
}是手加的,但是这是必须要写的,不然会造成
UITableView dataSource must return a cell from tableView:cellForRowAtIndexPa
这样的错误
浙公网安备 33010602011771号