简体   繁体   中英

UIView custom class isnt showed in UIViewController

I have an TutorialInitialView .xib, .m, .h UIView extended class, then I have a UIViewController and in the viewDidLoad I do the following:

TutorialInitialView *vti=[[TutorialInitialView alloc] initWithFrame:CGRectMake(10,10,300,300)];
[self.MBMeterContainer addSubview:vti];

But when I run in the simulator the TutorialInitialView doesn´t appear. What am I doing wrong?

You need to load the xib, not alloc init the class.

UINib *nib = [UINib nibWithNibName:"TutorialInitialView" bundle: nil];
TutorialInitialView *vti= [nib instantiateWithOwner:self options:nil][0];
[self.MBMeterContainer addSubview:vti];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM