xcode uitableview + 导航控制器从所选元素设置标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9670797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uitableview + navigation controller set title from selected element
提问by obithemaster
I have a UINnavigationController
that handles the navigation in a UITableView
.
我有一个UINnavigationController
处理UITableView
.
When I select a row from the table I need to display in the UINavigationController
title the selected item from the previous menu.
当我从表中选择一行时,我需要在UINavigationController
标题中显示上一个菜单中的所选项目。
The label of the cell is read from an external xml
that fills the rows of the UITableView
.
单元格的标签是从xml
填充UITableView
.
How can I display my selection on the title of the UINavigationBar
?
如何在 的标题上显示我的选择UINavigationBar
?
I've set a static title by using the self.title
command, but it doesn't fit my needs
我使用self.title
命令设置了静态标题,但它不符合我的需要
回答by FluffulousChimp
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];
}
回答by Alex Cio
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
:
Normaly的UINavigationController
总是挑选出title
了的UIViewController
已实际加载。这就是为什么你必须在里面定义它viewDidLoad
:
self.title = @"Title";
The method displayed above seems to be more dynamic...but this also works.
上面显示的方法似乎更动态……但这也有效。