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

发布于 2024-11-15 21:29:57 字数 2103 浏览 3 评论 0原文

在审查现有答案时,我认为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的背包 2024-11-22 21:29:57

由于您没有将此视图控制器推送到 UINavigationController 上,因此设置 newForm.navigationItem.title 不起作用。

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

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

    UINavigationBar *customNavBar;

和一个outlet属性

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

在IFDNewFormViewController.m中:

    @synthesize customNavBar;

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

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

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

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

否则 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

    UINavigationBar *customNavBar;

and an outlet property

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

In IFDNewFormViewController.m:

    @synthesize customNavBar;

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:

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

Or the data in the xib won't even be used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文