开发者

Display a uiview object in a window

开发者 https://www.devze.com 2023-01-14 13:25 出处:网络
hi am trying to display a uiview class object in the window but the thing is that its not being displayed don\'t know for what reason am not able to sort out please do help me out, here\'s my code

hi am trying to display a uiview class object in the window but the thing is that its not being displayed don't know for what reason am not able to sort out please do help me out, here's my code

    @interface Myview : UIViewController {


    UIView *move_view;

    UIButton *btn;



}


@end




#import "Myview.h"


@implementation Myview

 // The designated initializer.  Override if you create the controller programmatically and want to per开发者_如何学JAVAform customization that is not appropriate for viewDidLoad.
- (id)init {
    if (self = [super init]) {

        // Custom initialization
        [move_view setFrame:CGRectMake(41, 91, 64, 82)];
        [move_view setBackgroundColor:[UIColor redColor]];


        btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btn setFrame:CGRectMake(113, 298, 72, 37)];
        [btn setTitle:@"Move" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(moveaview) forControlEvents:UIControlEventTouchUpInside];

    }
    return self;
}



// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {

    [super loadView];
    [self.view addSubview:move_view];
    [self.view addSubview:btn];
}

Thank you


I guess you have to alloc+initialize the view in the init method. Also, are you sure you have alloc+init correctly the UIViewController and attached to the AppDelegate window? Some other remarks:

  • Do not call MyView a UIViewController subclass, the code is less understandable
  • If you are loading the Controller from a NIB/XIB you'd better ovverrid the method - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
0

精彩评论

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