您好,请问我是否可以在故事板中将 xib 与我的 UIViewController
混合使用?就像他们在文件所有者中共享一个 Controller 一样,因为我计划使用 nib 作为扩展 View 来创建可扩展 View ,并且我想将 nib 文件中的值传递到 Storyboard中的 UIViewController 。谢谢。
最佳答案
我不建议您将 xib 和 Storyboard中的 View Controller 混合在一起并将它们连接在一起。 如果您想将 UIView 作为扩展 View 添加到 View Controller 中,您可以执行以下操作:
// 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];
我希望我正确理解了你的意思。
关于ios - Storyboard中的 UIViewController 和 nib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21871703/