Objective c 如何在同一UITableViewCell中显示两行?

Objective c 如何在同一UITableViewCell中显示两行?,objective-c,ios,uitableview,Objective C,Ios,Uitableview,我试图在UITableView的同一表格行中显示两行文本 这可能吗 我尝试过不同的方法,但我找不到任何关于它的东西,也找不出答案。如果您能提供任何帮助,我们将不胜感激 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell";

我试图在
UITableView
的同一表格行中显示两行文本

这可能吗

我尝试过不同的方法,但我找不到任何关于它的东西,也找不出答案。如果您能提供任何帮助,我们将不胜感激

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

您可以在Apple中看到不同的样式,您可能需要的是UITableViewCellStyleSubtitle(指南中的图1-7)。请看一看

您可以使用
cell.detailTextLabel.text=@“我的文本”
设置第二个标签

你必须改变这条线路

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

使用正确的样式:UITableViewCellStyleSubtitle

编辑

要按注释中所述格式设置字符串,请执行以下操作:

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];

请查看有关如何设置数字格式等的更多详细信息。

您是否已经有了一些代码?请向我们展示,它更容易为您提供解决问题的提示。请在输出到行时查看我正在使用的UITable..'cell.textlab.text=p._name;'现在我想把p.x输出到同一个单元格。。。我该怎么做。。两者都是字符串。。。sry我是个新手…(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{static NSString*CellIdentifier=@“Cell”;UITableViewCell*Cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];if(Cell==nil){Cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]autorelease];}phonesAppDelegate*appDelegate=(phonesAppDelegate*)[[UIApplication sharedApplication]delegate];HLPFoundPhones*p=(HLPFoundPhones*)[appDelegate.\u phones对象索引:indexath.row];cell.textLabel.text=p.\u名称;cell.detailTextLabel.text=@“笑话”;//配置单元格。返回单元格;}是否正确。。?我无法运行它。。。我看不到较短的文本。请编辑您自己的问题,并将代码放在那里,然后用{}按钮格式化。在这些评论中缺少一些特征线。谢谢nick。。还有一件事。。我想在第二行显示两个字符串。。比如假设两个字符串位置和时间。。我想把它表现为。。在上找到;有关于plz的帮助吗?添加了一个示例,请查看NSStrings类文档。
NSString *subtitle = [NSString stringWithFormat:@"Found on location ("%f","%f") on date %@", p.x, p.y, p.date];