gpt4 book ai didi

iphone - 如何更改分组的 tableViewCell 的高度?

转载 作者:行者123 更新时间:2023-12-03 18:58:44 25 4
gpt4 key购买 nike

我正在尝试显示 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;
}

最佳答案

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

self.tableView.rowHeight = 100;

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

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

关于iphone - 如何更改分组的 tableViewCell 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com