在 iOS 应用程序中显示不同的 XIB/NIB

发布于 2024-11-17 19:00:23 字数 236 浏览 3 评论 0原文

我有多个 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 技术交流群。

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

发布评论

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

评论(1

疯狂的代价 2024-11-24 19:00:23

我处理实际 xib 之间切换的方法(我确信有多种方法可以完成同一件事)是让我的应用程序代理充当我的视图之间的路由中心。

我订阅我的应用程序委托来接收现有视图的按钮按下事件。当它收到切换视图的请求(例如按下按钮)时,我会执行以下操作:

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

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

    self.window.rootViewController = self.loginViewController;
}

将我的 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:

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

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

    self.window.rootViewController = self.loginViewController;
}

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.

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