2014-02-27 127 views
1

我描述了[self.view addSubView:myView];,
但是,myView沒有顯示self.viewaddSubview is not displayed UIView

ViewController.h

@interface ViewController : UIViewController{ 
    UIView *myView; 
} 

@property (nonatomic, strong) UIView *myView; 

ViewController.m

@synthesize myView; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    myView.frame = CGRectMake(-10, 70, 320, 480); 
    [self.view addSubview:myView]; 
    myView.backgroundColor = [UIColor redColor]; 
    [self.view bringSubviewToFront:myView]; 
} 

你有什麼辦法呢?

回答

4

您需要首先分配您的看法:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // If you use custom view change UIView to the custom class name 
    myView = [[UIView alloc] initWithFrame:CGRectMake(-10, 70, 320, 480)]; 

    [self.view addSubview:myView]; 
    myView.backgroundColor = [UIColor redColor]; 
    [self.view bringSubviewToFront:myView]; 
} 
+0

我解決了problem.Thank你。 –