在模态视图中设置导航项标题
在审查现有答案时,我认为 Steve 的问题和 codelark 的问题答案最接近我的问题。但我在这里遗漏了一些东西。
我的模式视图 xib: IFDNewFormViewController.xib:
View Controller
> Table View
>> View
>>> Navigation Bar
>>>> Navigation Item - New Form
>> View
>>> Toolbar
>>>> Bar Button Item - Cancel
>>>> Bar Button Item - Flexible Space
>>>> Bar Button Item - Done
按下按钮时调用的方法:
IFDNewFormViewController.m:
- (void) newFormDisplay:(id)sender {
// Show the Create Flightlog View
IFDNewFormViewController *newForm = [[IFDNewFormViewController alloc] init];
newForm.flightlogDelegate = self;
newForm.dataType = [self ifdDataType];
newForm.displayDataType = [NSString stringWithFormat:@"New %@",[self displayDataType]];
newForm.title = [NSString stringWithFormat:@"Title %@",[self displayDataType]];
newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];
NSLog(@"iFDListViewController_Pad:newFormDisplay start form for dataType=%@ (%@)",[self ifdDataType], [self displayDataType]);
[self presentModalViewController:newForm animated:YES];
[newForm release];
}
我已在 xib 中设置标题:
导航项 - 新表单 ->标题。
该标题是视图上显示的标题。使用在该论坛中找到的信息,我添加了以下几行:
newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];
仍然没有喜悦。
我在这里缺少一些东西。有什么想法吗?
In reviewing the existing answers, I think Steve's question and codelark's answer comes the closet to my issue. But I am missing something here.
My xib for the modal view:
IFDNewFormViewController.xib:
View Controller
> Table View
>> View
>>> Navigation Bar
>>>> Navigation Item - New Form
>> View
>>> Toolbar
>>>> Bar Button Item - Cancel
>>>> Bar Button Item - Flexible Space
>>>> Bar Button Item - Done
My method that gets called at a button press:
IFDNewFormViewController.m:
- (void) newFormDisplay:(id)sender {
// Show the Create Flightlog View
IFDNewFormViewController *newForm = [[IFDNewFormViewController alloc] init];
newForm.flightlogDelegate = self;
newForm.dataType = [self ifdDataType];
newForm.displayDataType = [NSString stringWithFormat:@"New %@",[self displayDataType]];
newForm.title = [NSString stringWithFormat:@"Title %@",[self displayDataType]];
newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];
NSLog(@"iFDListViewController_Pad:newFormDisplay start form for dataType=%@ (%@)",[self ifdDataType], [self displayDataType]);
[self presentModalViewController:newForm animated:YES];
[newForm release];
}
I have set the title in xib:
Navigation Item - New Form -> title.
That title is the one on displayed on the view. Using the information found in this forum I added the following lines:
newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];
Still no joy.
I am missing something here. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有将此视图控制器推送到 UINavigationController 上,因此设置 newForm.navigationItem.title 不起作用。
看起来您正在推动一个包含其自己的导航栏的模态视图控制器。在这种情况下,您可能需要创建自己的引用并将 xib 中的栏与其绑定。
在IFDNewFormViewController.h中创建一个实例变量
和一个outlet属性
在IFDNewFormViewController.m中:
一定要在dealloc中释放它并在viewDidUnload中设置为nil。
编辑 xib 时,右键单击导航栏,然后单击“新引用插座”旁边的空心圆圈并将其拖动到文件所有者处,然后选择 customNavBar。这样,加载后该属性将包含来自 xib 的栏。
当您初始化 IFDNewFormViewController 时,请务必使用以下内容:
否则 xib 中的数据甚至不会被使用。
Since you are not pushing this view controller onto a UINavigationController, setting newForm.navigationItem.title won't do the trick.
It looks like you are pushing a modal view controller that contains it's own navigation bar. In that case, you'll probably need to create your own reference to it and tie the bar in the xib to it.
In IFDNewFormViewController.h create an instance variable
and an outlet property
In IFDNewFormViewController.m:
Be sure to release it in dealloc and set to nil in viewDidUnload.
When editing the xib, right click on your navigation bar then click and drag the open circle next to "New Referencing Outlet" up to the file's owner and select customNavBar. That way the property will contain the bar from your xib after it is loaded.
When you init your IFDNewFormViewController, be sure to use the following:
Or the data in the xib won't even be used.