在“更多...”选项卡中选择的选项卡栏项目将获得标题“项目”

发布于 2024-12-18 20:29:04 字数 861 浏览 4 评论 0原文

我有一个应用程序委托,它也是 UINavigationControllerDelegate (并且在询问是否会触发某些工作之前,我尝试将其设置为 UITabBarControllerDelegate 和 UITabBarDelegate,但是......)。

在 mainwindow.xib 中,我有一个包含 6 个项目的选项卡栏,这些项目被分成 4 个 + 一个更多选项卡,其中包含两个剩余选项卡(在列表中),进入标准视图。

该选项卡栏有一个控制器,它是导航控制器的根控制器,称为 rootCt。

现在,问题是在“更多”导航控制中选择选项卡会使所选视图控制器的标题为零,显示“项目”而不是选项卡标题。

我想获得在 IB 中设置的标题,因为我已经制作了本地化的笔尖。即,只是您在“更多”视图中单击的标题。

我试过了:

UITabBarItem *item=[[appd rootCt].tabBar.items objectAtIndex:4];
NSString *str=[item title];
self.title=str;

但这给出了零。将索引更改为 3 会正确给出第三个标题,而 5 会导致崩溃。

尝试过:

NSString *str=[appd rootCt].selectedViewController.title;

这也给出了 nil,因为它还没有设置 - 这就是需要在此代码中设置的内容。

我无法使用 selectedViewController.title,因为它为零,而这正是我想要设置的。正确的?

如何从更多视图中获取选定的选项卡标题?有必要这么难吗??或者我错过了一些明显的事情......

I have an app delegate, which is also UINavigationControllerDelegate (and I've tried setting it as UITabBarControllerDelegate and UITabBarDelegate before asking, if that would trigger something to work, but...).

In mainwindow.xib, I have a tab bar with 6 items, which become split up into 4 + a more tab, which goes to the standard view with the two remaining tabs (in a list).

This tab bar has a controller which is the root controller over the nav controller, and called rootCt.

Now, the problem is that selected the tabs in the More nav ctlr makes the selected viewcontroller's title nil, showing "Item" instead of the tab title.

I would like to get the title as set in IB, as I've made localized nibs. Ie., simply the title that you click on in the More view.

I've tried:

UITabBarItem *item=[[appd rootCt].tabBar.items objectAtIndex:4];
NSString *str=[item title];
self.title=str;

But this gives nil. Changing index to 3 gives the 3rd title correctly, and 5 results in a crash.

Tried:

NSString *str=[appd rootCt].selectedViewController.title;

This also gives nil, because it's not set yet - that's what I need to set in this code.

I can't use selectedViewController.title, as that's nil and that's what I'm trying to set. Right?

How do I get the selected tab title coming from the More view? Should it be this hard?? Or have I missed something obvious...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

尐偏执 2024-12-25 20:29:04

首先,您尝试在哪里运行上面粘贴的代码?我们可能需要更多详细信息来帮助您。

设置标题的正确位置(如果您想覆盖 xib 中的设置,这听起来不像您想要做的!)位于正在显示的 UIViewController 中,在其 < code>viewDidLoad 或 viewDidAppear 方法。如果您使用viewWillAppear,则可能尚未设置。

但我觉得你的 xib 设置不正确。

您的另一个问题是您在 Xcode 中使用什么模板? “手动”设置所有这些东西比使用标准模板要困难得多。

First of all, where are you attempting to run the code you've pasted above? We probably need more detail to help you out here.

The correct place to set the title (if you wanted to overwrite what's set in the xib, which it doesn't sound like you want to do!) is in the UIViewController that's being displayed, in its viewDidLoad or viewDidAppear methods. If you use viewWillAppear, it may not be set yet.

But it really sounds to me like your xib isn't set up correctly.

Another question for you is what template did you start with in Xcode? It's significantly harder to set all this stuff up "by hand" than it is to use the standard template.

水溶 2024-12-25 20:29:04

它一定是丢失了插座参考或类似的东西。删除 .xib 并重做工作解决了这个问题。

It must have been a lost outlet reference or similar. Deleting the .xib and redoing the work solved it.

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