获取当前正在查看的iPhone xib的名称
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我尝试使用它
但它不起作用,而是尝试这个
I tried to use it with
But it won't work, instead try this
如果您说:
NSString *name = self.view.nibname
您可以使用 nibname来证明它
You can use the nibname
if you say:
NSString *name = self.view.nibname
you can proove it with您正在加载的视图控制器具有
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.ViewController 子类有一个 nibName 字符串属性,您可以检查:
ViewController subclasses have a nibName string property you can check against: