如何在与表中选择的行对应的详细视图中显示标题

时间:2010-01-29 09:38:01

标签: iphone objective-c uitableview uinavigationcontroller title

我是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图像”作为标题的标题。

请帮帮我。谢谢。

2 个答案:

答案 0 :(得分: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];
    }

答案 1 :(得分:1)

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

second.title = [tableList objectAtIndex:indexPath.row];