Hit*_*itz 5 iphone row-height uitableview
我正在尝试将地址显示为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;
}
Run Code Online (Sandbox Code Playgroud)
小智 4
要将所有单元格设置为相同的固定高度,请在 viewDidLoad 或其他适当的位置中执行以下操作:
self.tableView.rowHeight = 100;
Run Code Online (Sandbox Code Playgroud)
要根据索引路径将单元格设置为不同的高度,请使用 heightForRowAtIndexPath 委托方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ((indexPath.section == 0) && (indexPath.row == 0))
return 100;
else
return 44;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
810 次 |
| 最近记录: |