Я переопределил tableView:indentationLevelForRowAtIndexPath
метод в моем UITableViewController
производный класс следующим образом:
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary* item = [self.projects objectAtIndex:indexPath.row];
int indentationLevel = [[item objectForKey:@"indent"] intValue];
DLog (@"Indentation Level for Row %d : %d", indexPath.row, indentationLevel);
return indentationLevel;
}
Я первоначально думал, что это не называли, но это было ошибкой оператора (допустите ошибку, мой), и я не определил символ DEBUG=1.
Однако это называют (понятное дело меня!) и это - вывод журнала:
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 0 : 1
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 1 : 1
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 2 : 2
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 3 : 2
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 4 : 2
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 5 : 1
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 6 : 2
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 7 : 2
-[RootViewController tableView:indentationLevelForRowAtIndexPath:] [Line 129] Indentation Level for Row 8 : 1
Но, это не влияет на расположение ячеек. Никакое добавление отступа.
Это - мой itemCellForRowAtIndexPath
реализация, если это имеет какое-либо значение:
-(UITableViewCell*)tableView:(UITableView *)tableView itemCellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellIdentifier = @"projectItemCell";
ProjectItemTableViewCell* cell = (ProjectItemTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"ProjectItemTableViewCell" owner:self options:nil];
for (id oneObject in nib) {
if ([oneObject isKindOfClass:[ProjectItemTableViewCell class]]) {
cell = (ProjectItemTableViewCell*)oneObject;
}
}
}
NSDictionary* item = [self.projects objectAtIndex:indexPath.row];
cell.projectDescLabel.text = [item objectForKey:@"name"];
cell.itemCountlabel.text = [NSString stringWithFormat:@"%d", [[item objectForKey:@"cache_count"] intValue]];
cell.itemCountlabel.backgroundColor = [UIColor colorForHex:[item objectForKey:@"color"]];
cell.indentationWidth = 20;
return cell;
}
Как я располагаю пользовательское с отступом UITableViewCell
который я определил в Интерфейсном Разработчике?
Если я изменяюсь itemCellForRowAtIndexPath
использовать значение по умолчанию UITableViewCell
с кодом ниже, затем это делает отступ прекрасный.
static NSString* cellIdentifier = @"projectItemCell";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
}
NSDictionary* item = [self.projects objectAtIndex:indexPath.row];
cell.textLabel.text = [item objectForKey:@"name"];
cell.indentationWidth = 40;
return cell;
Уровень отступа является свойством Сам UITableViewCell
. Попробуйте установить его в ячейке при ее создании и вернуть это значение в tableView: indentationLevelForRowAtIndexPath:
Вы добавили подпредставления вашего ProjectItemTableViewCell в contentView ячейки? Кроме того, вам необходимо установить маски автоизменения размеров подвидов, чтобы они перемещались при изменении размера contentView.
Вы случайно переопределили shouldIndentWhileEditing: с
по НЕТ
в пользовательском классе ячеек таблицы?