views:

234

answers:

2

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 selected, the corresponding view should display the title has "iphone image" below the navigation bar as title for header.

Please help me out.Thanks.

A: 

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

second.title = [tableList objectAtIndex:indexPath.row];
Ole Begemann
This will display the title in navigation bar but i want the title to be displayed below the navigation bar( like title in titleforHeader method)
Warrior
Alright, sorry that I misread your question. Declare a string property in your detail view controllers and assign the title to it when you create the controller. Then put a UILabel on the view and in the view controller's viewDidLoad, assign the string as the label text. I don't really see what the problem is here.
Ole Begemann
+2  A: 

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];
    }
BK
@TechZen thanks for that. newbie. dint know how to do that.
BK