ios - 在模态视图中设置导航项标题

标签 ios uinavigationbar uinavigationitem

在查看现有答案时,我认为 Steve's question and codelark's answer来解决我的问题。但我在这里遗漏了一些东西。

模态视图的 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中设置了标题:

导航项 - 新表单 -> 标题。

该标题是显示在 View 上的标题。使用在此论坛中找到的信息,我添加了以下几行:

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]];

仍然没有快乐。

我在这里遗漏了一些东西。有什么想法吗?

最佳答案

由于您没有将此 View Controller 推送到 UINavigationController 上,因此设置 newForm.navigationItem.title 不会成功。

看起来您正在插入一个包含其自己的导航栏的模态视图 Controller 。在这种情况下,您可能需要创建自己的引用并将 xib 中的栏绑定(bind)到它。

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

    UINavigationBar *customNavBar;

还有一家奥特莱斯酒店

    @property (nonatomic, retain) IBOutlet *UINavigationBar customNavBar;

在 IFDNewFormViewController.m 中:

    @synthesize customNavBar;

一定要在dealloc中释放,在viewDidUnload中设置为nil。

编辑 xib 时,右键单击您的导航栏,然后单击“New Referencing Outlet”旁边的空心圆并将其拖动到文件所有者,然后选择 customNavBar。这样,该属性将在加载后包含来自您的 xib 的栏。

当您初始化 IFDNewFormViewController 时,请务必使用以下内容:

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

否则xib中的数据根本用不到。

关于ios - 在模态视图中设置导航项标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6373360/

相关文章:

ios - 添加为 subview 时如何为交叉溶解 View 设置动画?

objective-c - 隐藏的导航栏导致操作表出现问题

ios - UINavigationController 阴影

ios - 如何在按下导航栏时快速隐藏键盘

ios - 将 backButtonBarItem 替换为 leftBarButtonItem

ios - 网络扩展查看打印报表

ios - 带有推送通知的应用提交到应用商店

iphone - 导航栏中的信息灯按钮

ios - 我的 UINavigationitem 的 TitleView 在 ios 6 中得到扩展

ios - 如何根据另一个 var 检查数组的内容,通过 if 语句利用警报窗口?