擷取Storyboard中單獨的控制器,擷取storyboard

來源:互聯網
上載者:User

擷取Storyboard中單獨的控制器,擷取storyboard

最近碰到一個問題,需求如下:

需求:在某個storyboard中有一個單獨的控制器VC(沒有連線),在storyboard中給此VC隨便拖幾個控制項在上面,同時自訂一個類綁定此VC,問如何擷取到此VC並且顯示storyboard中此VC設定的介面。如:

 

1,首先要知道是哪個storyboard,先介紹一下storyboard的三個方法:

1> 下面的方法表示通過storyboard的名字從某個包中擷取(一般設定為nil表示從主包中擷取)storyboard
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil

2> 此方法擷取到storyboard中初始的控制器
- (id)instantiateInitialViewController 

3> 此方法表示通過控制器的identifier擷取到此控制器,新版本的Xcode用Storyboard ID來表示某個控制器的identifier
- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier; 

好了,從上面的三個方法應該很多朋友都知道怎麼擷取Storyboard中單獨的控制器了。

 

2,在storyboard中設定此單獨的VC的identifier,即Storyboard ID,用於區分storyboard中的控制器,如

                 

 

3,在類中調用storyboard中的-instantiateViewControllerWithIdentifier:方法擷取次單獨的VC

ZJDuLiController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DuLi"]

 

4,push或modal出次VC即可

[self.navigationController pushViewController:vc animated:YES];

最終效果如下:

                              

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.