简体   繁体   English

如何将单元格添加到tableview中

[英]how to add to cell into tableview

is it possible to add 2 cell.textlabel into the table view. 是否可以将2个cell.textlabel添加到表视图中。 As i want trying to display 3 different lines. 因为我想尝试显示3条不同的线条。 Here the code i did : 这里的代码我做了:

- (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;
}

but when i put two cell.textLabel.text it got an error bad access . 但是当我把两个cell.textLabel.text放到错误的bad access what should i do? 我该怎么办? Pls help 请帮忙

You only call cell.textLabel.text once, but put a \\n in your string where you want a line break. 您只需调用cell.textLabel.text一次,但在字符串中放置一个\\ n,您想要换行符。

You also have an error in your stringWithFormat -- either put an @ in front of "Walk to and board at" or just remove that first %@, and have : 你的stringWithFormat中也有一个错误 - 要么在“Walk to and board at”前面放一个@,要么只删除第一个%@,并且:

stringWithFormat:@"Walk to and board at %@",[boardDescArray objectAtIndex:indexPath.row]]; stringWithFormat:@“走到并登上%@”,[boardDescArray objectAtIndex:indexPath.row]];

So, to make it 2 lines you want this: 所以,为了使它成为2行你想要这个:

cell.textLabel.text = [NSString stringWithFormat:@"Walk to and board at %@\nAlight Destination = %@",[boardDescArray objectAtIndex:indexPath.row],[alDescArray objectAtIndex:indexPath.row]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM