我试图用分组表格查看简单的UIPopover。一切都很好,但第一行是空的,它的数据在最后一行。我的代码有什么问题?UITableView创建第一行最后
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];
static NSString *kCellTextField_ID = @"CellTextField_ID";
cell = [tableView dequeueReusableCellWithIdentifier:kCellTextField_ID];
if (cell == nil) {
// a new cell needs to be created
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellTextField_ID] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else {
// a cell is being recycled, remove the old edit field (if it contains one of our tagged edit fields)
UIView *viewToCheck = nil;
viewToCheck = [cell.contentView viewWithTag:kViewTag];
if (viewToCheck) [viewToCheck removeFromSuperview];
}
if (section == 1 && row == 0) {
UITextView *textView = [[self.sisalto objectAtIndex: row] valueForKey:kViewKey];
[cell.contentView addSubview:textView];
} else {
UITextField *textField = [[self.sisalto objectAtIndex: row] valueForKey:kViewKey];
[cell.contentView addSubview:textField];
}
return cell;
}
为什么当你在两个方向完全相同时,你需要if的“section”和“row”? – jodm 2011-03-14 13:33:23
@jodm他们不完全一样。 'UITextView' vs'UITextField' – 2011-03-14 14:09:45