[英]how to add to cell into 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:@“走到並登上%@”,[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]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.