How can I display two rows in the same UITableViewCell?

I am trying to show two lines of text in the same line table UITableView.

Can this be done?

I tried different things, but I can not find or understand anything. Any help you can provide will be appreciated.

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    phonesAppDelegate *appDelegate = (phonesAppDelegate *)[[UIApplication sharedApplication] delegate];
    HLPFoundPhones *p = (HLPFoundPhones *)[appDelegate._phones objectAtIndex:indexPath.row];

    NSString *subtitle = [NSString stringWithFormat:@"Found on location (",p.x,@",",p.y,@") on date ", p.date];

    cell.textLabel.text = p._name;
    cell.detailTextLabel.text = subtitle;

    return cell;
}
+3
source share
1 answer

You can see a different style in the Apple Table Programming Guide for iOS , you may need the UITableViewCellStyleSubtitle (Figure 1-7 in the guide). Please look.

You can set the second mark with cell.detailTextLabel.text = @"my text".

You need to change this line

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

to

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

using the correct style: UITableViewCellStyleSubtitle.

EDIT

, :

NSString *location = @"a Location";
NSString *date = @"20m ago";
NSString *subtitle = [NSString stringWithFormat:@"%@ on %@", location, date];

2

NSString *subtitle = [NSString stringWithFormat:@"Found on location ("%f","%f") on date %@", p.x, p.y, p.date];

, / String , ..

+4

All Articles