繁体   English   中英

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

[英]UIViewController in storyboard with nib file

嗨,我可以问我是否可以将xib与故事板中的UIViewController混合使用吗? 就像他们在文件所有者中共享一个控制器一样,因为我计划通过使用nib作为expandview创建一个可扩展视图,并且我想将nib文件中的值传递给Storyboard中的UIViewController 谢谢。

我不建议您混合使用xib和情节提要中的View Controller并将它们挂在一起。 如果要将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];

我希望我能正确理解你。

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

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

暂无
暂无

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

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