Я создаю табличное представление сгруппированного стиля
, и таблица имеет 5 разделов, и каждый раздел имеет различное количество строк
Вот мой код
1.Укажите, какмного разделов в таблице
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 5;
}
2.Установите все строки в разделе
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0:
return 1;
break;
case 1:
return 2;
break;
case 2:
return 3;
break;
case 3:
return 1;
break;
case 4:
return 2;
break;
default:
return 1;
}
}
3.Дайте заголовок раздела:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return @"Section 1";
break;
case 1:
return @"Section 2";
break;
case 2:
return @"Section 3";
break;
case 3:
return @"Section 4";
break;
case 4:
return @"Section 5";
break;
default:
return nil;
}
}
5.Толькодать первую строку в данных первого раздела (потому что другие, у меня пока нет идеи установить ячейку)
- (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];
}
if (indexPath.section==0 && indexPath.row==0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"About System";
}
return cell;
}
, чем я получил две одинаковые ячейки в Разделе 0, Строке 0 и Разделе 4, Строке 0
Но если I пометить заголовок раздела
Текстовая метка появляется только в секции 0 Строка 0
IS логическая ошибка моего переключателя?или просто вопрос компилятора ????