如何动态更改标签栏项目的标签(iPhone dev)

发布于 2024-12-29 17:56:39 字数 171 浏览 4 评论 0原文

我正在使用 XCode 4.1 并且我已经有一个 iPhone 应用程序。

在“MainWindow.xib”的界面构建器中,有一个导航控制器。其中有一个带有标题的选项卡栏项目。我需要动态更改这个标题。但是,似乎没有与 MainWindow.xib 关联的“.h”文件,因此我不知道如何访问该对象。有什么想法吗?

I'm using XCode 4.1 and I have an already existing IPhone app.

In the "MainWindow.xib", in the Interface builder, there is a Navigation Controller. Inside it, a Tab Bar Item with a title on it. I need to change this title dynamically. However, there seems to be no ".h" file associated with the MainWindow.xib, so I have no idea how to access this object. Any idea?

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

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

发布评论

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

评论(2

美煞众生 2025-01-05 17:56:39

您不需要 .h 文件来访问 MainWindow.xib 中的项目。您可以在应用程序委托中为要访问的项目声明 IBOutlet。 MainWindow.xib 中的对象之一是应用程序委托,因此您可以将 elementos 分配给其 IBOutlet。

You don't need a .h file to access items in MainWindow.xib. You can declare IBOutlets in your app delegate for the items you want to access. One of the objects in MainWindow.xib is the app delegate, so you can assign elementos to its IBOutlets.

听风吹 2025-01-05 17:56:39

主窗口或选项卡栏 bontroller 在某种程度上与另一个控制器相关(与 .h 和 .m 文件关联)。

因此,在这个控制器中,我添加了以下代码:

UIViewController *uvButton1 = [self.tabBarController.viewControllers objectAtIndex:0];
uvButton1.tabBarItem.title = NSLocalizedString(@"KEY", nil);

对于另外 2 个控制器,依此类推(将索引“0”更改为“1”和“2”);

NSLocalizedString 函数转到本地化文件 (Localized.strings) 并根据键选择正确的文本。您也可以在那里使用标准字符串。

The main window or the tab bar bontroller was, somehow, related to another controller (associated with a .h and .m file).

So in this controller, I added this code :

UIViewController *uvButton1 = [self.tabBarController.viewControllers objectAtIndex:0];
uvButton1.tabBarItem.title = NSLocalizedString(@"KEY", nil);

and so on for the 2 others (changing the index "0" for "1" and "2");

the NSLocalizedString function goes to a localized file (Localizable.strings) and chooses the right text based on the key. You can also just use a standard string there.

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