Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uitableview + navigation controller set title from selected element

I have a UINnavigationController that handles the navigation in a UITableView.

When I select a row from the table I need to display in the UINavigationController title the selected item from the previous menu.

The label of the cell is read from an external xml that fills the rows of the UITableView.

How can I display my selection on the title of the UINavigationBar?

I've set a static title by using the self.title command, but it doesn't fit my needs

like image 408
obithemaster Avatar asked May 02 '26 20:05

obithemaster


2 Answers

Would this work for you?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    DetailTableViewController *detailController = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    //   Set the detail controller title to whatever you want here...
    detailController.title = @"Your title";

    //   Or set it to the title of this row
    UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:indexPath];
    detailController.title = cell.textLabel.text;

    [[self navigationController] pushViewController:detailController animated:YES];
}
like image 173
FluffulousChimp Avatar answered May 05 '26 09:05

FluffulousChimp


Normaly the UINavigationController always picks out the title of the UIViewController which has been actually loaded. Thats why you have to define it inside viewDidLoad:

self.title = @"Title";

The method displayed above seems to be more dynamic...but this also works.

like image 20
Alex Cio Avatar answered May 05 '26 10:05

Alex Cio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!