Как изменить высоту сгруппированной ячейки просмотра таблицы?

#iphone #uitableview #row-height

#iPhone #uitableview #высота строки

Вопрос:

Я пытаюсь отобразить адрес так, как он отображается в приложении Contact на iPhone. итак, кажется, мне нужна ячейка высотой в три раза больше обычной ячейки. поскольку она всегда будет одинаковой, мне просто нужно применить фиксированную высоту к коду. но я не знаю, как это сделать. мой текущий код

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *address = [NSString stringWithFormat:@"%@n"@"%@ %@ %@n"@"%@", dispAddress, dispCity, dispState, dispZip, dispCountry];
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    }


    // Configure the cell...

        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.detailTextLabel.numberOfLines = 3; // 0 means no max.
        cell.detailTextLabel.text = address;

    return cell;
}
  

Ответ №1:

Чтобы установить для всех ячеек одинаковую фиксированную высоту в viewDidLoad или в каком-либо другом подходящем месте, выполните:

 self.tableView.rowHeight = 100;
  

Чтобы задать ячейкам разную высоту в зависимости от пути к индексу, используйте метод делегирования heightForRowAtIndexPath:

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ((indexPath.section == 0) amp;amp; (indexPath.row == 0))
        return 100;
    else
        return 44;
}
  

Комментарии:

1. Большое спасибо Анна, heightForRowAtIndexPath сработал идеально. Большое спасибо.