xcode 按下按钮时如何加载另一个xib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3961575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load another xib when pressing a button
提问by user421704
I have a project where where i have one ViewController and two xib files. I have two buttons on a view which is shown in the viewcontroller. Both buttons are active and returning a NSLog so i know they are working. Basically I would like to load a xib when the button is pressed. I have a view setup in each xib.
我有一个项目,其中有一个 ViewController 和两个 xib 文件。我在视图控制器中显示的视图上有两个按钮。两个按钮都处于活动状态并返回 NSLog,所以我知道它们正在工作。基本上我想在按下按钮时加载一个 xib。我在每个 xib 中都有一个视图设置。
Thanks for your help in advance!
提前感谢您的帮助!
回答by Costique
Send [[NSBundle mainBundle] loadNibNamed: @"MyXib" owner: self options: nil] from your view controller. When the xib gets loaded the view controller will connect its Interface Builder outlets as specified in the xib. Make sure that in IB you've set the class of File Owner to your view controller's class and connected the outlets you need.
从您的视图控制器发送 [[NSBundle mainBundle] loadNibNamed: @"MyXib" owner: self options: nil]。当xib 被加载时,视图控制器将按照xib 中的规定连接其Interface Builder 出口。确保在 IB 中您已将 File Owner 的类设置为您的视图控制器的类并连接了您需要的插座。