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: