国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大丰市| 砀山县| 宜都市| 娱乐| 张家口市| 南开区| 资溪县| 增城市| 乌鲁木齐县| 嘉黎县| 大方县| 普兰店市| 九龙县| 平湖市| 昭觉县| 伽师县| 疏勒县| 襄城县| 福安市| 沙河市| 石门县| 望江县| 遵化市| 奈曼旗| 眉山市| 青冈县| 和田县| 广灵县| 顺昌县| 那曲县| 蓝田县| 灵丘县| 富川| 富蕴县| 黔东| 靖边县| 洪江市| 汉沽区| 滦平县| 湟源县| 扎赉特旗|