iphone - 如何将单元格添加到tableview

标签 iphone objective-c ios uitableview xcode4.3

是否可以在 TableView 中添加 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。我应该怎么办? 请帮忙

最佳答案

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

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

stringWithFormat:@"Walk to and board at %@",[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]];

关于iphone - 如何将单元格添加到tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11927198/

相关文章:

iphone - 如何在不启动的情况下在ios应用程序之间发送获取数据

iphone - 是否有通过打开应用程序一部分的 web View 创建链接?

ios - 分配并初始化 destinationViewController

ios - mkmapview 在指定帧中显示路线和注释

iOS 如何在inputview改变时获取键盘高度?

iphone - 如何实现一个由左侧图像和右侧文本组成的 UIButton

android - 如何使用 Corona SDK 在单个页面上加载超过 32 种声音

iphone - 获取路由器范围内设备的MAC地址

ios - iOS 和 android 上的 AES 加密,输出和缓冲区大小不同

ios - 如何在swift3中用其他元素替换数组的值?