开发者

View is not loading

开发者 https://www.devze.com 2023-03-26 21:14 出处:网络
MoviePlayerAppDelegate.m - (void)applicationDidFinishLaunching:(UIApplication *)application { window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

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:UIControl开发者_StackOverflow中文版EventTouchUpInside];
    [[self view] addSubview:playButton];
}

But somehow view is not loading. I could not find mistake in code. Please help to resolve this. Thanks in advance.


Try this:

Remove the code

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

and change addSubView as below.

[self.window addSubview:viewController.view];

[self.window makeKeyAndVisible];


You can try to define UIView in your header file a then attache it to 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];
}

this definitely works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号