嗨,请问我是否可以将 xib 与我UIViewController
的 in storyboard 混合使用?就像他们在他们的文件所有者中共享一个控制器一样,因为我计划通过使用 nib 作为扩展视图来创建一个可扩展视图,并且我想将一个值从 nib 文件传递到UIViewController
故事板中。谢谢。
问问题
1039 次
2 回答
4
我不建议您将情节提要中的 xib 和视图控制器混合在一起并将它们连接在一起。如果您想将 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];
我希望我正确地理解了你。
于 2014-02-19T08:10:57.957 回答
0
In storyboard you are not provided with xibs, but if you want to use them to load from nib then use :
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"CustomDownloadedXib" bundle:nil];
于 2014-02-19T07:20:55.410 回答