不使用nib 文件时,需要改变一个view 的大小时,需要为viewcontroller添加loadView方法

- (void)loadView{
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view setBackgroundColor:[UIColor whiteColor]];
}

 注意:不能将 loadView 方法中的代码写在  - (void)viewDidLoad ,一定要为viewController方法添加一个loadView方法。

其他viewController 调用上述 viewController时,可以通过以下方法进行

-(IBAction)searchButtonOnClicked:(id)sender
{
    NSLog(@"开始查询");
    
//    ResultVC *myResultVC = [[ResultVC alloc]initWithNibName:nil bundle:nil];
    ResultVC *myResultVC = [[ResultVC alloc]init];
    myResultVC.nsma_result = nsma_selectedSerachContent;
    self.resultVC = myResultVC;
    [self.view addSubview:self.resultVC.view];
}
原文地址:https://www.cnblogs.com/ygm900/p/3163466.html