5

我正在尝试显示地址,因为它显示在 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;
}
4

1 回答 1

4

要将所有单元格设置为相同的固定高度,请在 viewDidLoad 或其他适当的位置执行以下操作:

self.tableView.rowHeight = 100;

要根据索引路径将单元格设置为不同的高度,请使用 heightForRowAtIndexPath 委托方法:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ((indexPath.section == 0) && (indexPath.row == 0))
        return 100;
    else
        return 44;
}
于 2011-04-26T02:16:23.973 回答