获取当前正在查看的iPhone xib的名称

发布于 2024-10-03 01:51:54 字数 374 浏览 1 评论 0原文

我有 3 个 xib 文件连接到同一个类,以减少重复编码。然而,当新的 nib 文件加载时(即在 ViewDidLoad 方法中),我想要完成一些不同的事情。我考虑过做一个 if 语句来将当前显示的 xib 名称与字符串进行比较。我一整天都在试图弄清楚如何做到这一点,但我没有任何运气。如果这让您感到困惑,这里有一些伪代码:

if (currentXibInDisplay == @"XibFileName1")
   // Do This...
else if (currentXibInDisplay == @"XibFileName2")
   // Do This...

有一种方法可以做到这一点,对吧?这看起来很简单,但我现在很困惑。感谢您提供的任何信息。

I have 3 xib files connected to the same class to reduce duplicate coding. However, there are different stuff that I want done when the new nib file loads (i.e. in the ViewDidLoad method). I've thought about doing an if statement to compare the name of the xib currently being displayed to a string. I have been trying to figure out how to do that for most of the day but I haven't had any luck. Here's some pseudo code if that confused you:

if (currentXibInDisplay == @"XibFileName1")
   // Do This...
else if (currentXibInDisplay == @"XibFileName2")
   // Do This...

There is a way to do that, right? It seems pretty simple but I am pretty stumped right now. Thanks for any info you can provide.

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

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

发布评论

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

评论(4

始终不够爱げ你 2024-10-10 01:51:54

我尝试使用它

self.view.nibName;

但它不起作用,而是尝试这个

self.nibName;

I tried to use it with

self.view.nibName;

But it won't work, instead try this

self.nibName;
成熟的代价 2024-10-10 01:51:54

如果您说: NSString *name = self.view.nibname您可以使用 nibname

来证明它

`[name isEqual:@"XIBName"]`

You can use the nibname

if you say: NSString *name = self.view.nibname you can proove it with

`[name isEqual:@"XIBName"]`
薔薇婲 2024-10-10 01:51:54

您正在加载的视图控制器具有 initWithNibNamed: 方法,您可以覆盖该方法并存储要加载的 XIB。

The view controller that you're loading has the initWithNibNamed: method, you can override there and store which XIB is going to be loaded.

情仇皆在手 2024-10-10 01:51:54

ViewController 子类有一个 nibName 字符串属性,您可以检查:

[self.nibName isEqualTo:@"XIBFileName"]

ViewController subclasses have a nibName string property you can check against:

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