1

我是 iphone 开发的新手。我在表格中显示一组数据。单击该行后,它将导航到相应的详细信息视图。我想在详细视图中显示与表中所选行相对应的标题。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if([[tableList objectAtIndex:indexPath.row] isEqual:@"Display The Text"])
    {  
        secondviewcontroller *second= [[secondviewcontroller alloc] initWithNibName:@"secondviewcontroller" bundle:nil];
        [self.navigationController pushViewController:second animated:YES];
    }

    if([[tableList objectAtIndex:indexPath.row] isEqual:@"iPhone Image"])
    {  
        thirdviewcontroller *third= [[thirdviewcontroller alloc] initWithNibName:@"thirdviewcontroller" bundle:nil];
        [self.navigationController pushViewController:third animated:YES];
    }
}

如果选择了“显示文本”,则相应的导航视图应将其标题设置为导航栏下方的“显示文本”作为标题的标题,如果选择了“iphone 图片”,则相应的视图应显示标题导航栏下方的“iphone 图片”作为标题的标题。

请帮帮我。谢谢。

4

2 回答 2

2

在您的 secondviewcontroller 和 thirdviewcontroller 中声明一个字符串属性,并添加以下代码。它应该可以正常工作。

if([[tableList objectAtIndex:indexPath.row] isEqual:@"Display The Text"])
    {  
        secondviewcontroller *second= [[secondviewcontroller alloc] initWithNibName:                          
                           @"secondviewcontroller" bundle:nil];  
         [self.navigationController pushViewController:second animated:YES];
         second.lblTitle = [tableList objectAtIndex:indexPath.row];
    }


    if([[tableList objectAtIndex:indexPath.row] isEqual:@"iPhone Image"])
    {  
        thirdviewcontroller *third= [[thirdviewcontroller alloc] initWithNibName:@"thirdviewcontroller" bundle:nil];
        [self.navigationController pushViewController:third animated:YES];
         third.lblTitle = [tableList objectAtIndex:indexPath.row];
    }
于 2010-01-29T11:39:09.733 回答
1

在将视图控制器推送到导航堆栈之前设置它的标题。在你的情况下:

second.title = [tableList objectAtIndex:indexPath.row];
于 2010-01-29T10:29:22.670 回答