xCode - 更改 2 个现有 xib 文件之间的视图

发布于 2024-10-21 17:25:37 字数 392 浏览 1 评论 0原文

我对 xCode 和 Objective-C 很陌生,所以我想制作一个简单的文本角色扮演游戏。

我目前正在制作一个由 4 个 xib 文件组成的角色创建过程。我切换视图的唯一方法是查看实用程序模板。问题是,现在我的第一个屏幕是第二个屏幕的代表,第三个屏幕的代表等等。因此,在角色创建过程结束时,我无法忽略视图,因为这只是“后退”的意见。

当我四处寻找解决方案时,我找到了一个 addSubview 方法,但似乎这使得一个新视图(如)为空,无法以编程方式排列。

我所需要的只是一种从一个加载的 xib 切换到另一个 xib 的简单方法。我是否误解了 addSubview 或者我需要完全不同的东西?

(如果有帮助的话:我已经使用 VB 好几年了,如果你注意到我错过了一些关于视图等的概念) 提前致谢! :)

I'm very new to xCode and objective-C so I wanted to make a simple textRPG.

I'm currently making a character creation process consisting of 4 xib-files. The only way I got switching views to work was to look at the utility-template. Problem is, now I have the first screen being the delegate for the second screen, being the delegate for the third screen etc. So by the end of the character creation process I can't dismiss the views because that just "steps back" through the views.

When I've searched around for a solution I've found a addSubview-method but it seems like that makes a new view, like, empty to arrange programmatically.

All I need is a simple way to switch from one loaded xib to another xib. Have I misunderstood addSubview or do I need something completely different?

(If it helps: I've worked with VB for several years, in case you notice that I missed some kind of concept concerning views and such)
Thanks in advance! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

入画浅相思 2024-10-28 17:25:37

使用此代码。它非常简单并且效果很好。

  View *view = [[View alloc] initWithNibName:@"xibNameGoesHere" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:view animated:YES completion:nil];

这将切换到另一个 xib 文件,并且两个视图不会相互拥有。我现在正在自己的游戏中使用它。

Use this code. It is really simple and works well.

  View *view = [[View alloc] initWithNibName:@"xibNameGoesHere" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:view animated:YES completion:nil];

This will switch to another xib file and the two views won't own one another. I am using it in my own game right now.

花期渐远 2024-10-28 17:25:37

@Joakim 好吧,这就是我这样做的方式。我有一个名为 RootViewController : UIViewContoller 的类,我将其视图直接添加到窗口中。然后我创建了 UIView 的子类,即 MyView。我所有的视图然后子类化 MyView。我还对我所有的观点进行了枚举。在 RootViewController 中,您应该有一个 switchView:(int)view 方法,如下所示:

    -(void) switchView:(myView) view
    {
        [_currentView removeFromSuperview];

        switch(view)
        {
            case titleView:
            _currentView = [[TitleView alloc] initWithRoot:self];
            break;
            case homeView:
            _currentView = [[HomeView alloc] initWithRoot:self];
            break;
            default: break;
        }
        [self.view addSubview:_currentView];
        [_currentView release];
    }

在 @interface RootViewContoller 中定义 MyView *_currentView;
TitleView 和 HomeView 都是 MyView 的子类,并且有一个通用方法 -(id)initWithRoot:(RootViewController*) rvc。

要在视图之间切换,请使用 [_rvc switchView:homeView];
希望这有帮助:)

@Joakim Ok, this is the way I do it. I have a class called RootViewController : UIViewContoller, whose view I add directly to the window. Then I make a subclass of UIView i.e. MyView. All of my views then subclass MyView. I also make an enum for all my views. In RootViewController you should have a switchView:(int)view method that looks something like this:

    -(void) switchView:(myView) view
    {
        [_currentView removeFromSuperview];

        switch(view)
        {
            case titleView:
            _currentView = [[TitleView alloc] initWithRoot:self];
            break;
            case homeView:
            _currentView = [[HomeView alloc] initWithRoot:self];
            break;
            default: break;
        }
        [self.view addSubview:_currentView];
        [_currentView release];
    }

in @interface RootViewContoller define MyView *_currentView;
TitleView and HomeView both subclass MyView and have a common method -(id)initWithRoot:(RootViewController*) rvc.

To switch between views use [_rvc switchView:homeView];
Hope this helps :)

避讳 2024-10-28 17:25:37

它称为 UINavigationController。想法是

1)每次用户提交当前屏幕时,将相应的“下一个”控制器推送到导航控制器中。奖励 - 您将在角色创建的每一步中免费获得“后退”按钮。

2) 创建角色后,从堆栈中弹出所有角色创建控制器。

请阅读 视图控制器在尝试“切换视图”等之前,先阅读 iOS 编程指南。您将节省大量时间和精力。

It is called UINavigationController. Idea is

1) You push corresponding 'next' controller into navigation controller each time user submits current screen. Bonus - you'll get 'back' button for free on each step of character creation.

2) After character is created you pop all character creation controllers from stack.

Please read View Controller Programming Guide for iOS before trying to 'switch views' and such. You'll save tons of time and nerves.

妄断弥空 2024-10-28 17:25:37

另一个想法是根本不使用界面生成器。我已经使用 iPhone 应用程序工作两年了,发现界面生成器确实延长了实际制作东西的时间。创建您自己的根控制器并考虑浏览视图所需的逻辑。

another idea is not to use interface builder at all. i have been working with iphone apps for two years now and found that interface builder really prolongs the time to actually make something. make your own root controller and think about the logic you need to navigate through the views.

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