Ios 在模式视图中设置导航项标题

Ios 在模式视图中设置导航项标题,ios,uinavigationbar,uinavigationitem,Ios,Uinavigationbar,Uinavigationitem,在回顾现有的答案时,我想我的问题就隐藏起来了。但我在这里遗漏了一些东西 模态视图的我的xib: IFDNewFormViewController.xib: View Controller > Table View >> View >>> Navigation Bar >>>> Navigation Item - New Form >> View >>> Toolbar >>>> Ba

在回顾现有的答案时,我想我的问题就隐藏起来了。但我在这里遗漏了一些东西

模态视图的我的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]];
还是没有快乐


我错过了一些东西。有什么想法吗?

因为您没有将此视图控制器推送到UINavigationController上,所以设置newForm.navigationItem.title不会起作用

看起来您正在推送一个包含自己导航栏的模态视图控制器。在这种情况下,您可能需要创建自己对它的引用,并将xib中的条绑定到它

在IFDNewFormViewController.h中创建一个实例变量

    UINavigationBar *customNavBar;
和一个出口财产

    @property (nonatomic, retain) IBOutlet *UINavigationBar customNavBar;
在IFDNewFormViewController.m中:

    @synthesize customNavBar;
确保在dealoc中释放它,并在viewDidUnload中设置为nil

编辑xib时,右键单击导航栏,然后单击并拖动“新引用出口”旁边的开放圆,直到文件的所有者,然后选择customNavBar。这样,属性将在加载后包含来自xib的条

在初始化IFDNewFormViewController时,请确保使用以下命令:

    IFDNewFormViewController *newForm = [[IFDNewFormViewController] alloc] initWithNibName:@"whatever-the-file-name-is" bundle:nil];

或者甚至不会使用xib中的数据。

我已经添加了建议的代码。我需要在@property行中添加类型。在分配IFDNewFormViewController之后,当我设置标题时,没有错误,但是xcode从.title=行末尾设置的断点显示,“newFormNavBar(UINavigationBar*)0x0”。我在xib中验证了,当单击视图控制器->表视图->视图->导航栏时,在引用Outlets:newFormNavBar下,我确实对@tlbrack提供的解决方案进行了一些更改,使其正常工作。变化:1。我引用了UINavigationItem,2。移动行:
newFormNavItem.title=[NSString stringWithFormat:@“title%@,[self-displayDataType]]到<代码>视图将在IFDNewFormViewController.m中显示:(BOOL)动画
。为什么newFormNavItem不在`IFDNewFormViewController*newForm=[[IFDNewFormViewController]alloc]initWithNibName:@“无论文件名是什么”bundle:nil]之后初始化;`叫什么名字?我应该为这个问题添加一个带有最终更改的解决方案,还是将@tlbrack's标记为解决方案?