ios - Storyboard中的 UIViewController 和 nib 文件

标签 ios xcode storyboard nib expandable

您好,请问我是否可以在故​​事板中将 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/

相关文章:

ios - Tensorflow 构建 iOS sh 错误

ios - 如何实用地将信号连接到 ios 中的插槽?

ios - 'Apple Developer Program License Agreement' 已更新

ios - 如何像 Path Talk 应用程序一样编写设置 View Controller ?

iphone - 在 iOS 6 上更改 TextView 的默认内容的正确方法是什么?

iphone - 如何在 iPhone 中将 HTML 读取为 XML

iPhone dSYM 崩溃日志符号

ios - 原始类型的枚举不能有带参数的案例

ios - 在 ScrollView 上添加圆形按钮

iphone - Storyboard中的自定义字体?