简体   繁体   中英

how to add to cell into tableview

is it possible to add 2 cell.textlabel into the table view. As i want trying to display 3 different lines. 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 . 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.

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 %@",[boardDescArray objectAtIndex:indexPath.row]];

So, to make it 2 lines you want this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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