UIView addSubview and the preview is not displayed

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    HeadViewController *headViewController = [[HeadViewController alloc] initWithNibName:@"HeadViewController" bundle:nil];    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
    [view addSubview:headViewController.vew];
    [self.view addSubview:view];
}

HeadViewController.h:

@interface HeadViewController : UIViewController
{
    IBOutlet UIView *view;
}
@property (nonatomic, retain)IBOutlet UIView *view;
@end

and I will connect the view to the owner of the file.

And I do not see headViewController.view.

+5
source share
3 answers

First of all, you do not need to determine the output viewin the class HeadViewController. It is automatically inherited from the superclass UIViewController.

Then I suggest you add a direct view HeadViewControllerto your current view. For instance.

- (void)viewDidLoad
{
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
     HeadViewController *headViewController = [[HeadViewController alloc] initWithNibName:@"HeadViewController" bundle:nil];    
     headViewController.view.frame = CGRectMake(0, 0, 320, 120);
     [self.view addSubview:headViewController.view];
}

, ARC (Automatic Reference Counting), HeadViewController, , viewDidLoad. ( , ) , . , , , . - :

- (void)viewDidLoad
{
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
     self.headViewController = [[HeadViewController alloc] initWithNibName:@"HeadViewController" bundle:nil];    
     headViewController.view.frame = CGRectMake(0, 0, 320, 120);
     [self.view addSubview:headViewController.view];
}

@interface MyController ()
    @property (nonatomic, strong) HeadViewController *headViewController;
@end

.m.

+15

- .view

[ addSubview: headViewController.vew];

0

i is missing from the syntax

[view addSubview: headViewController.view];

0
source

All Articles