国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用代碼調用Storyboard里面的viewController

2019-11-14 18:29:53
字體:
來源:轉載
供稿:網友

  今天在幫助群里的一個朋友弄pop事件,在他那邊,當前的viewcontroller,不能pop出去。

  初步估計,他的ViewController層級多,他自己沒有理清。

  因為pushViewController的時候,是執行棧入的原則,先進后出,后進先出。

  比如A->B->C->D,他這個時候,想popB,但是B的上面還有兩個,分別為C和D,C和D沒有出來,這個時候,B就沒有辦法出來。所以,即使執行了pop語句,也達不到pop的效果。

  

  然后中午我自己用storyboard拖了幾個東西,簡單實現了這個效果,發現自己對storyboard還是不太熟,要仔細實踐??!

 

  1.  調出storyboard方法:
UIStoryboard * mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

Parameters

name

The name of the storyboard resource file without the filename extension. This method raises an exception if this parameter is nil.

storyboardBundleOrNil

The bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application.

Return Value

A storyboard object for the specified file. If no storyboard resource file matching name exists, an exception is thrown with description: Could not find a storyboard named 'XXXXXX' in bundle....

Discussion

Use this method to retrieve the storyboard object containing the view controller graph you want to access. All of the resources associated with the storyboard must be in the bundle indicated by the storyboardBundleOrNil parameter.

  • Name則是自己起的,在.storyboard前面的名字,如果不動,則默認是Main,而且不需要添加文件的擴展名,如果加了,就會報錯;
  • bundle:這個參數包含storyboard的文件以及和它相關的資源,如果為空,則會調用當前程序的main bundle

這樣,就能拿到程序里面的storyboard了。

 

  2.調出里面的viewcontroller

 

  我是在里面直接拖拽了幾個viewcontroller,當需要加載這幾個viewcontroller的時候,有3件事情要做

    2.1 新建ViewController的.h和.m文件,并且將storyboard里面的nib文件的class,也指向對應的VC;

    2.2 設置Storyboard ID,在Custom Class下面,有一個Identity,這個設置標識符,我們就可以找到它了,像Cell的標識符,一般和頭文件名稱設置為一樣就可以。

    2.3 在代碼里面調用它:

UIStoryboard * mainStoryBoard =[UIStoryboard storyboardWithName:@"Main" bundle:nil];DViewController * dVC = [mainStoryBoard instantiateViewControllerWithIdentifier:@"DViewController"];[self.navigationController pushViewController:dVC  animated:YES];

  這樣就可以了。功能就基本實現了。

  

熟能生巧--歡迎大家加入我們的交流群:461093715


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 莫力| 镇雄县| 同江市| 鸡东县| 阳谷县| 柘荣县| 庆云县| 镇赉县| 博客| 江城| 四子王旗| 临江市| 昆明市| 克什克腾旗| 东至县| 长兴县| 分宜县| 藁城市| 仁寿县| 翼城县| 南木林县| 江油市| 伊吾县| 鄂托克前旗| 林周县| 马边| 建昌县| 乌鲁木齐县| 资阳市| 独山县| 靖州| 顺平县| 高邑县| 满洲里市| 那曲县| 凭祥市| 山西省| 敦化市| 尖扎县| 抚顺县| 玛多县|