今天在幫助群里的一個朋友弄pop事件,在他那邊,當前的viewcontroller,不能pop出去。
初步估計,他的ViewController層級多,他自己沒有理清。
因為pushViewController的時候,是執行棧入的原則,先進后出,后進先出。
比如A->B->C->D,他這個時候,想popB,但是B的上面還有兩個,分別為C和D,C和D沒有出來,這個時候,B就沒有辦法出來。所以,即使執行了pop語句,也達不到pop的效果。
然后中午我自己用storyboard拖了幾個東西,簡單實現了這個效果,發現自己對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.
這樣,就能拿到程序里面的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
新聞熱點
疑難解答