我已经创建了一个默认的 UITableViewCell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Init empty cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:GroupCellIdentifier];
// Get the group info
GroupInfo *groupInfo = (GroupInfo *)[_sortedGroupInfos objectAtIndex:[indexPath row]];
// Check if we have initialized this cell before
if(cell == nil)
{
// Initialize cell
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:GroupCellIdentifier];
// Set the accessory type
cell.accessoryType = UITableViewCellAccessoryNone;
// Set the selection type
cell.selectionStyle = [groupInfo.groupType isEqualToString:GroupTypePersonal] ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;
// Set the indentation width
cell.indentationWidth = 40;
}
// Set the label enabled status depending on the group type
cell.textLabel.enabled = [groupInfo.groupType isEqualToString:GroupTypePersonal];
cell.detailTextLabel.enabled = [groupInfo.groupType isEqualToString:GroupTypePersonal];
// Set text
cell.textLabel.text = groupInfo.description;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d %@", groupInfo.storeCount, [[Model instance] getTranslationFromSection:kSectionStoreSettings translationKey:@"Stores"]];
// Set the image depending on the group type
cell.imageView.image = [GroupInfo getImageForGroupType:groupInfo.groupType];
// Return the cell
return cell;
}
我还实现了 indentationLevelForRowAtIndexPath 函数:
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get the group info
GroupInfo *groupInfo = _sortedGroupInfos[[indexPath row]];
// Return the indentation
return groupInfo.indentation;
}
现在我得到以下表格视图:
http://i40.tinypic.com/f3e63t.png
我的问题是:为什么图像在表格视图单元格中没有缩进?