开发者

How to display the title in detail view corresponding to the row selected in the table

I am new to iphone development. I am displaying an array of data in a table. Upon clicking the row, it navigates to the corresponding detail view. I want to display a title in the detail view corresponding to the row selected in the table.

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

If "display the text" is selected, the corresponding navigated view should have it's title set to "display the text" below the navigation bar as title for a header and if "iphone image" is se开发者_如何学JAVAlected, the corresponding view should display the title has "iphone image" below the navigation bar as title for header.

Please help me out.Thanks.


In your secondviewcontroller and thirdviewcontroller declare a string property, and add the following code. It should work fine.

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


Set your view controller's title before pushing it on the navigation stack. In your case:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜