I created this view controller which has a XIB file, and contains a UIButton.
I alloc and init the controller, and add the view to the superview:
- (void)viewDidLoad
{
[super viewDidLoad];
self.vc = [[MyViewController alloc]init];
[self.view addSubview:self.vc.view];
CGRect frame;
frame.size.height = 200;
frame.size.width = 200;
frame.origin.x = 100;
frame.origin.y = 100;
self.vc.view.frame = frame;
[vc setText:@"123"];
}
When I run this, the UIButton is not shown. When I debug this, and put breakpoints in my controller’s viewDidLoad or viewDidAppear, the UIButton is always uninstantiated (memory adress 00000000);
what can be the problem?
Your
MyViewControllershould be initialised with the XIB file: