简体   繁体   English

带有Nib文件的情节提要中的UIViewController

[英]UIViewController in storyboard with nib file

Hi can I ask if can I mix the xib with my UIViewController in storyboard? 嗨,我可以问我是否可以将xib与故事板中的UIViewController混合使用吗? 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. 就像他们在文件所有者中共享一个控制器一样,因为我计划通过使用nib作为expandview创建一个可扩展视图,并且我想将nib文件中的值传递给Storyboard中的UIViewController Thanks. 谢谢。

I don't recommend you mix xib and view controller from storyboard and hook them all together. 我不建议您混合使用xib和情节提要中的View Controller并将它们挂在一起。 If you want to add a UIView as an extended view to your view controller you can do something like this: 如果要将UIView作为扩展视图添加到视图控制器,则可以执行以下操作:

// 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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