Set Nav Bar's Title From Array
I have a rootTableView with cells that are loaded from an array:
logArray = [[NSArray alloc]initWithObjects:@"John", @"Jack", @"Jill", nil];
When I click a cell, for example the cell called "Jack", it will take me to a sub table for "Jack"
How to 开发者_运维百科I set the title of that sub tableView to "Jack", etc.
Under the tableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NextViewController *nextView = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
**nextView.title = [logArray objectAtIndex: indexPath.row];**
//push the nextView here
}
I think you can try using the UITableView
section header for this
You need to create a property in your sub tableview that you can pass the name along to. Something like this should be in your didSelectRowAtIndexPath method.
UITableViewCell *currentCell = [self.tableView cellForRowAtIndexPath:indexPath];
MySubtableviewController *mstvc = [[MySubTsbleViewController alloc] init];
mstvc.nameProperty = currentCell.textLabel.text;
[self.navigstiomController pushViewController:mstvc];
Something like that where the nameProperty is declared in your sub tableView controller. Then in your sub view controller, just set the title in viewDidLoad.
self.title = self.nameProperty;
Hope this helps.
精彩评论