【发布时间】:2014-05-16 00:33:02
【问题描述】:
我开始编写项目时并没有真正使用故事板(因为我正在学习有关为游戏创建选项菜单的教程)。
所以我试图追溯实现一种在 2 个 UIViewControllers(MainGame 和 MatchScreen)之间移动的方式,每个 UIView(分别为MainMenu 和 VSComputer)。
现在在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