【问题标题】:moving between 2 UIViewControllers each with 1 UIView - XCode5 osx在 2 个 UIViewController 之间移动,每个都有 1 个 UIView - XCode5 osx
【发布时间】:2014-05-16 00:33:02
【问题描述】:

我开始编写项目时并没有真正使用故事板(因为我正在学习有关为游戏创建选项菜单的教程)。

所以我试图追溯实现一种在 2 个 UIViewControllers(MainGameMatchScreen)之间移动的方式,每个 UIView(分别为MainMenuVSComputer)。

现在在MainMenu UIView 中,我创建了 4 个按钮,包括它们的所有位置和设置,其中两个是子视图 - 选项和统计信息 - 当单击当前 ViewController 时会出现和消失。

现在,问题是,我需要使用名为“matchScreen”的其他按钮之一以某种方式从主菜单移动到匹配屏幕。我觉得我一定缺少一些东西,因为在我的研究中没有找到对我有用的答案。

我已经将我的主要UIViewController 嵌入了navController(正如我在其他问题中所建议的那样),然后向第二个ViewController 添加了一个push segue。但我不知道如何使这对我的代码显而易见。我的代码似乎无法识别我在情节提要中所做的任何事情。

@interface JDTHMainMenu(){

JDTHOptionsScreen *theOptionScreen;
JDTHPlayerStats *thePlayerStatsScreen;
UIButton *optionScreenButton;
UIButton *matchScreenButton;
UIButton *deckScreenButton;
UIButton *statsScreenButton;
bool isPhone;
bool isOptionScreenOpen;
bool isPlayerStatsScreenOpen;
bool matchScreenButtonPressed;
UIView *tint;
int screenWidth;
int screenHeight;

AppData *appData;

}

所以要明确一点,JDTHMainMenu 是 JDTHViewController 中的一个 UIView - 原来,JDTHMatchScreen 是第二个 ViewController,并且有一个 UIView 称为 JDTHVersusScreen。我试图从一个到另一个。此外,JDTHAppDelegate 仅在 didFinishLaunching 方法中返回 YES。我觉得我越来越近了......但也许不是......

-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code

    appData = [AppData sharedData];
    NSLog(@"Main Menu has loaded");

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        isPhone = YES;
    } else {
        isPhone = NO;
    }

    screenWidth = self.frame.size.width;
    screenHeight = self.frame.size.height;
    isOptionScreenOpen = NO;
    isPlayerStatsScreenOpen = NO;
    matchScreenButtonPressed = NO;
    [self showOptionScreenButton];
    [self showPlayerStatsScreenButton];
    [self matchViewControllerButton:matchScreenButton];
    [self deckViewerControllerButton:deckScreenButton];

}
return self;

}

-(IBAction)matchViewControllerButton:(UIButton *)sender{
CGRect rect;
UIFont *theFont;


if (isPhone == YES) {
    rect = CGRectMake(38, 150, 134, 116);
    theFont = [UIFont fontWithName:@"Zapfino" size:22];
} else {
    rect = CGRectMake(275, 600, 200, 150);
    theFont = [UIFont fontWithName:@"Zapfino" size:28];
}

matchScreenButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[matchScreenButton addTarget:self action:@selector(goToMatchView:sender:) forControlEvents:UIControlEventTouchDown];
[matchScreenButton.titleLabel setFont:theFont];
[matchScreenButton setTitle:@"VS Comp" forState:UIControlStateNormal];
matchScreenButton.frame = rect;
[matchScreenButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[matchScreenButton setBackgroundImage:[UIImage imageNamed:@"MainMenuOptionButton"] forState:UIControlStateNormal];

[self addSubview:matchScreenButton];

}

-(void)goToMatchView:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"pushToMatchView"]) {
    JDTHMatchScreen *vc2 = (JDTHMatchScreen *)segue.destinationViewController;
    vc2.name = self.textField.text;
}

}

【问题讨论】:

    标签: ios objective-c macos uiviewcontroller xcode5


    【解决方案1】:

    情节提要应用程序在 info.plist 文件中有一个条目,该条目告诉应用它是情节提要应用程序,情节提要的名称是什么(“主情节提要文件基本名称”是键的名称,而value 是故事板的文件名,不带扩展名)。您需要将此添加到您的项目中以使其识别情节提要。此外,非故事板应用程序通常在应用程序委托中有代码来设置初始控制器。这应该为情节提要应用程序删除(在 didFinishLaunchingWithOptions: 中默认模板中的唯一代码是“返回 YES”)。启动一个新的基于故事板的单视图项目并将文件复制到其中可能会更容易。

    【讨论】:

    • 很高兴知道,这就是我的项目的设置方式,但我的问题的主要部分仍然是一个问题。我需要从一个视图控制器中的一个视图移动到另一个视图控制器中的另一个视图,我不知道如何编写代码。
    • @JonHerbert,好吧,如果您添加了 push segues,它现在应该可以工作(假设您的应用程序现在正在识别您的故事板)。你有没有从一个按钮连接到下一个控制器?
    • 我做了,是的,我编辑了我的 OP 并将我的一些代码放在那里,这样你就可以看到了。在情节提要中,我制作了一个按钮,然后按 ctrl 将其拖到 MatchScreen ViewController。现在我已经有代码描述了按钮的外观和 UIView 上的位置(这就是为什么这都是追溯的),现在我正试图将所有这些信息放在那里。我会告诉你我的意思
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多