如何在另一个视图控制器中加载xib文件的视图

时间:2017-06-16 11:14:01

标签: ios objective-c iphone

Xib文件

@interface SearchingPropertyViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIView *searchingView

我将以下代码添加到另一个ViewController中的按钮操作

SearchingPropertyViewController *ps    = [[[NSBundle mainBundle] loadNibNamed:@"SearchingPropertyViewController" owner:self options:nil] objectAtIndex:0];

[self.view addSubview:ps.searchingView];

我只是想在另一个视图控制器中加载searchView

1 个答案:

答案 0 :(得分:0)

试试这个!简单的解决方案:)请查找视图控制器loadview方法。 https://developer.apple.com/documentation/uikit/uiviewcontroller/1621454-loadview

         SearchingPropertyViewController *searchPVC = [[SearchingPropertyViewController alloc]initWithNibName:@"SearchingPropertyViewController" bundle:nil ];
        [searchPVC loadView];
        [self.view addSubview:searchPVC.textLabel];