简体   繁体   中英

UIViewController in storyboard with nib file

Hi can I ask if can I mix the xib with my UIViewController in storyboard? Like they share a controller in their files owner because I'm planning to create a expandable view by using nib as the expandedview and I want to pass a value from nib file to the UIViewController in storyboard. Thanks.

I don't recommend you mix xib and view controller from storyboard and hook them all together. If you want to add a UIView as an extended view to your view controller you can do something like this:

// Load the first view inside our xib from main bundle
UIView *view = [[NSBundle mainBundle] loadNibNamed:@"nib_name" owner:self options:nil][0];

// Define new X,Y to our view
float new_x_position = 0;
float new_y_position = 400;
view.frame = CGRectMake(new_x_position, new_y_position, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame));

// UILabel inside our nib, '111' is the tag we set to our UILabel
UILabel *label = (UILabel*)[view viewWithTag:111];

// Add our view to the current view as a sub view
[self.view addSubview:view];

I hope I understood you correctly.

在情节提要中,没有为您提供xibs,但如果要使用它们从nib加载,请使用:

MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"CustomDownloadedXib" bundle:nil];

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