부모 인 "GameViewCController"로부터 상속받은 "TapRaceViewController"라는 ViewController가 있습니다. 그러나 TapRaceViewControllers 하위보기 중 하나도 표시되지 않습니다. GameController의보기 만 표시됩니다. 왜 그런가요? TapRacerViewController의 viewDidLoad에 호출되고, 그래서 파단이 추가되지 않는 이유는 표시되지 않습니다.ViewController에 뷰가 표시되지 않습니다.
//
// TapRacerViewController.h
// MiniGame
//
// Created by Software Engineering on 11/16/14.
//
//
#import "GameViewController.h"
@interface TapRacerViewController : GameViewController
@end
TapRacerViewController.m
//
// TapRacerViewController.m
// MiniGame
//
// Created by Software Engineering on 11/16/14.
//
//
#import "TapRacerViewController.h"
@interface TapRacerViewController()
@end
@implementation TapRacerViewController
{
//A single tap on the screen
UITapGestureRecognizer* singleTap;
//the player
UILabel* player;
//The view
UIView* m_baseView;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Create the base view
m_baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[m_baseView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:m_baseView];
//Create the tap gesture
singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap)];
[m_baseView addGestureRecognizer:singleTap];
//Create the player
player = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 50, self.view.bounds.size.height/2, 50, 50)];
[player setBackgroundColor:[UIColor blackColor]];
[m_baseView addSubview:player];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//Handles a tap
- (void) handleSingleTap
{
NSLog(@"Tap!");
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
그리고 GameViewController,
//
// GameViewController.h
// MiniGame
//
// Created by Software Engineering on 11/16/14.
//
//
#import <UIKit/UIKit.h>
@interface GameViewController : UIViewController
//Base init
-(id) initWithDifficulty:(int)difficulty;
//On each tick
-(void) onTick;
@end
GameViewController .m
//
// GameViewController.m
// MiniGame
//
// Created by Software Engineering on 11/16/14.
//
//
#import "GameViewController.h"
@interface GameViewController()
@end
@implementation GameViewController
{
//Timer
NSTimer* m_timer;
//Counter of the timer
float m_timerCounter;
//How long the minigame lasts
float m_time;
//Base view
UIView* m_baseView;
//How often a tick occurs
float m_tick;
//Text that tells the user what to do
UILabel* m_instructionLabel;
}
//Base initialization
-(id) initWithDifficulty:(int)difficulty
{
NSLog(@"Heyea");
//Base initialization
self = [super init];
if(self)
{
if(difficulty == 1)
{
m_time = 5.0f;
}
else if(difficulty == 2)
{
m_time = 4.0f;
}
else
{
m_time = 3.0f;
}
//Set the timer counter to 0.0f;
m_timerCounter = 0.0f;
//Set the tick frequency to 0.001f;
m_tick = 0.001f;
//Set the base view
m_baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[m_baseView setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:m_baseView];
//Set the default instruction text
m_instructionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[m_instructionLabel setText:@"Instruction!"];
[m_instructionLabel setFont:[UIFont fontWithName:@"Georgia-BoldItalic" size:15.0]];
[m_instructionLabel setTextColor:[UIColor redColor]];
[m_baseView addSubview:m_instructionLabel];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
//When the view loads, start the countdown
-(void) viewDidAppear:(BOOL)animated
{
//Start the timer
m_timer = [NSTimer scheduledTimerWithTimeInterval:m_tick target:self selector:@selector(onTick) userInfo:nil repeats:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//On every tick from m_timer
- (void)onTick
{
// NSLog(@"Tick!");
// NSLog(@"%.2f", m_timerCounter);
//Incriment the alpha of the text
if(m_instructionLabel.alpha > 0.7) {
[m_instructionLabel setAlpha:m_instructionLabel.alpha - 0.001];
}
//Incriment the timer counter by a tick
m_timerCounter += m_tick;
//If the timer counter is more than the alloted time for the mini game, quit the mini game
if(m_timerCounter > m_time)
{
//Stop the timer
[m_timer invalidate];
m_timer = nil;
//Dismiss this view controller
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
음. 'self.view'의 서브 뷰에'm_baseView'를 추가하지 않았습니까? – sikhapol
TapRacerViewController에 m_baseView를 추가 해보십시오. – Viper
생각하기 전에 게시하기 전에 그것을 다시 넣습니다. 좋았어.하지만 보여주지는 마. 혼란을 막기 위해 코드를 업데이트했습니다. –