Вид не загружается - PullRequest
       2

Вид не загружается

0 голосов
/ 08 августа 2011

MoviePlayerAppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    viewController = [[MoviePlayerViewController alloc] init];
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

MoviePlayerViewController.m

-(void)loadView {
    //Setup the view.
    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
    [[self view] setBackgroundColor:[UIColor grayColor]];
    [[self view] setUserInteractionEnabled:YES];

    //Add play button.
    playButton = [[UIButton alloc] initWithFrame:CGRectMake(53, 212, 214, 36)];
    [playButton setBackgroundImage:[UIImage imageNamed:@"playButton.png"] forState:UIControlStateNormal];
    [playButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:playButton];
}

Но почему-то view не загружается.Я не смог найти ошибку в коде.Пожалуйста, помогите решить эту проблему.Заранее спасибо.

Ответы [ 2 ]

0 голосов
/ 08 августа 2011

Попробуйте это:

Удалить код

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

и измените addSubView, как показано ниже.

[self.window addSubview:viewController.view];

[self.window makeKeyAndVisible];
0 голосов
/ 08 августа 2011

Вы можете попытаться определить UIView в вашем заголовочном файле, а затем прикрепить его к self.view

MoviePlayerViewController.h
UIView *contentView;

@property (retain, nonatomic) UIView                    *contentView;

MoviePlayerViewController.m

@synthesize contentView;

- loadView {

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

contentView = [[UIView alloc] initWithFrame:screenRect];
contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

self.view = contentView;
[contentView release];
}

это определенно работает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...