故事板中的UIViewController与nib文件

时间:2014-02-19 05:18:42

标签: ios xcode storyboard nib expandable

您好我可以问我是否可以将xib与我的UIViewController混合在故事板中?就像他们在文件所有者中共享一个控制器一样,因为我打算通过使用nib作为expandedview创建一个可扩展的视图,我想将一个值从nib文件传递到storyboard中的UIViewController。感谢。

2 个答案:

答案 0 :(得分: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];

我希望我能正确理解你。

答案 1 :(得分:0)

在故事板中,您没有提供xib,但如果您想使用它们从笔尖加载,请使用:

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