寫在前面的話
近期接到這樣一個(gè)需求,需要為app內(nèi)機(jī)構(gòu)詳情頁提供2種不同的布局,效果圖如下,
拿到該需求后,你都有哪些思路?
1司恳、創(chuàng)建2個(gè)
UIViewController
, 界面xib
實(shí)現(xiàn),邏輯代碼貼貼貼髓帽。2田度、創(chuàng)建1個(gè)
UIViewController
,純代碼實(shí)現(xiàn)。3、創(chuàng)建1個(gè)
UIViewController
昧谊, 不同場(chǎng)景加載不同的storyboard
或者xib
實(shí)現(xiàn)。我們采取第三種方法實(shí)現(xiàn)酗捌,那就引出了今天的問題呢诬,iOS控制器
ViewControlle
加載都有幾種方式?
代碼實(shí)現(xiàn)
通過alloc
或者new
方法實(shí)現(xiàn)胖缤。
故事板加載
在Main.storyboard
實(shí)現(xiàn)如下截圖
代碼實(shí)現(xiàn)部分
#import "AHTestViewController.h"
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AHTestViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"AHDemo2"];
在跳轉(zhuǎn)到機(jī)構(gòu)詳情頁時(shí)只需按照不同場(chǎng)景加載不同故事板即可.
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實(shí)現(xiàn)
新建一xib
文件,在xib
文件中做如下設(shè)置
代碼實(shí)現(xiàn)部分
#import "AHTestViewController.h"
AHTestViewController *vc = [[AHTestViewController alloc]initWithNibName:@"AHTest" bundle:nil];