0

是否可以将 2 添加cell.textlabel到表格视图中。因为我想尝试显示 3 条不同的线。这是我做的代码:

- (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];
}
cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size
cell.textLabel.numberOfLines = 2;
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@","Walk to and board at ",[boardDescArray objectAtIndex:indexPath.row]]; 
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@","Alight Destination = ",[alDescArray objectAtIndex:indexPath.row]]; 
return cell;
}

但是当我放两个cell.textLabel.text时它出错了bad access。我该怎么办?请帮忙

4

1 回答 1

2

您只调用一次 cell.textLabel.text ,但在您想要换行的字符串中放置一个 \n 。

您的 stringWithFormat 中也有一个错误——要么在“Walk to and board at”前面放一个@,要么只删除第一个 %@,然后:

stringWithFormat:@"步行到 %@ 并登机",[boardDescArray objectAtIndex:indexPath.row]];

因此,要使其成为您想要的 2 行:

cell.textLabel.text = [NSString stringWithFormat:@"Walk to and board at %@\nAlight Destination = %@",[boardDescArray objectAtIndex:indexPath.row],[alDescArray objectAtIndex:indexPath.row]];
于 2012-08-13T01:26:06.500 回答