在 iOS 应用程序中显示不同的 XIB/NIB
我有多个 nib (xib) 文件,我希望用户在点击按钮时看到不同的文件。我在寻找什么:
- (IBAction)buttonTap {
//Code for showing a different nib goes here
}
我不知道该怎么做。我可以在笔尖文件中显示不同的视图,但我无法让它显示不同的笔尖。当用户点击按钮时如何显示不同的笔尖?
任何帮助表示赞赏!谢谢!
I have multiple nib (xib) files and I want the user to see a different one when they tap a button. What I am looking for:
- (IBAction)buttonTap {
//Code for showing a different nib goes here
}
I can't figure out how to do this. I can show a different view within the nib file just fine, but I can't get it to show a different nib. How do I show a different nib when the user taps a button?
Any help is appreciated! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我处理实际 xib 之间切换的方法(我确信有多种方法可以完成同一件事)是让我的应用程序代理充当我的视图之间的路由中心。
我订阅我的应用程序委托来接收现有视图的按钮按下事件。当它收到切换视图的请求(例如按下按钮)时,我会执行以下操作:
将我的 rootViewController 设置为我尝试显示的视图。它不会释放旧的控制器,而只是替换正在显示的视图。您可以放置更多逻辑来确定它是否已显示,关闭其他视图等。用最简单的术语来说,这对我有用。
The way I handle switching between actual xib's, and I'm sure there are a multitude of ways to accomplish the same thing, is to have my App Delegate act as a routing center between my views.
I subscribe my App Delegate to recieve events from button presses for existing views. When it recieves a request to switch views, such as a button press, I do something like this:
I set my
rootViewController
to the view I am attempting to display. It doesn't release the old controller, but simply replaces the view being displayed. You can place more logic in to determine if it's already displayed, close out other views, etc. In most simplistic terms, this works for me.