寫在前面的話
近期接到這樣一個需求,需要為app內(nèi)機構(gòu)詳情頁提供2種不同的布局,效果圖如下,

機構(gòu)詳情頁的2種布局.png
拿到該需求后,你都有哪些思路?
1、創(chuàng)建2個
UIViewController, 界面xib實現(xiàn),邏輯代碼貼貼貼。2、創(chuàng)建1個
UIViewController,純代碼實現(xiàn)。3、創(chuàng)建1個
UIViewController, 不同場景加載不同的storyboard或者xib實現(xiàn)。我們采取第三種方法實現(xiàn),那就引出了今天的問題,iOS控制器
ViewControlle加載都有幾種方式?
代碼實現(xiàn)
通過alloc或者new方法實現(xiàn)。
故事板加載
在Main.storyboard實現(xiàn)如下截圖

故事板加載控制器.png
代碼實現(xiàn)部分
#import "AHTestViewController.h"
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AHTestViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"AHDemo2"];
在跳轉(zhuǎn)到機構(gòu)詳情頁時只需按照不同場景加載不同故事板即可.
if (item.organ_style.integerValue==1){
OrganOtherDetailViewController *VC = [[OrganOtherDetailViewController alloc]initWithType:detailone];
VC.item =self.orgaDataArr[indexPath.section];
[self.navigationController pushViewController:VC animated:YES];
}else if (item.organ_style.integerValue==2){
OrganOtherDetailViewController *VC = [[OrganOtherDetailViewController alloc]initWithType:detailtwo];
VC.item =self.orgaDataArr[indexPath.section];
[self.navigationController pushViewController:VC animated:YES];
}
xib實現(xiàn)
新建一xib文件,在xib文件中做如下設(shè)置

xib加載控制器.png
代碼實現(xiàn)部分
#import "AHTestViewController.h"
AHTestViewController *vc = [[AHTestViewController alloc]initWithNibName:@"AHTest" bundle:nil];