在iOS应用中显示不同的XIB / NIB [英] Showing a different XIB/NIB in an iOS app

查看:55
本文介绍了在iOS应用中显示不同的XIB / NIB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个nib(xib)文件,我希望用户在点击按钮时看到另一个。我在找什么:

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
}

我无法弄清楚如何做到这一点。我可以在nib文件中显示不同的视图就好了,但我不能让它显示不同的笔尖。当用户点击按钮时如何显示不同的笔尖?

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!

推荐答案

我处理实际xib之间切换的方式,我确信有很多种方法可以实现同样的事情,就是让我的App Delegate充当我的观点之间的路由中心。

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.

我订阅我的App Delegate来接收现有视图按钮按下的事件。当它收到切换视图的请求时,例如按下按钮,我会这样做:

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:

- (void) showLogin
{  
    LoginViewController *loginViewController = [[LoginViewController alloc]
                                                   initWithNibName:@"LoginViewController" bundle:nil];

    // Show
    self.loginViewController = loginViewController;
    [loginViewController release];

    self.window.rootViewController = self.loginViewController;
}

我设置 rootViewController 到我试图显示的视图。它不会释放旧控制器,而只是替换正在显示的视图。您可以放置​​更多逻辑来确定它是否已经显示,关闭其他视图等。在大多数简单的术语中,这对我有用。

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.

这篇关于在iOS应用中显示不同的XIB / NIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆