storyboard 如何用代码调用
轉(zhuǎn)自網(wǎng)絡(luò):
?
1、得到一個(gè)storyboard對(duì)象(UIStoryBoard類的對(duì)象)。
如果你有一個(gè)已經(jīng)存在的view controller,而且這個(gè)view controller是從同一個(gè)storyboard實(shí)例化而來(lái)的,那么可以通過(guò)它的storyboard屬性獲得storyboard對(duì)象。要加載另外一個(gè)storyboard對(duì)象,可以調(diào)用UIStoryboard的類方法storyboardWithName:bundle: ,并將storyboard文件的文件名和一個(gè)可選的bundle作為參數(shù)傳給該方法。
?
2、調(diào)用storyboard對(duì)象的instantiateViewControllerWithIdentifier: 方法,將你在Interface Builder中創(chuàng)建view controller時(shí)定義的標(biāo)識(shí)符傳給這個(gè)方法。
或者,你可以使用instantiateInitialViewController方法來(lái)實(shí)例化storyboard的首個(gè)view controller,而不用指定標(biāo)識(shí)符。
?
3、顯示這個(gè)新的view controller。
==============
一下用代碼解釋更清楚:
==============
如何在代碼中,調(diào)用一個(gè)已經(jīng)在storyboard中設(shè)計(jì)好的scene呢?代碼如下:
NSString * storyboardName = @"MainStoryboard_iPhone"; NSString * viewControllerID = @"ViewID"; UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil]; MyViewController * controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID]; [self presentViewController:controller animated:YES completion:nil];轉(zhuǎn)載于:https://www.cnblogs.com/memorecool/p/4056869.html
總結(jié)
以上是生活随笔為你收集整理的storyboard 如何用代码调用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: wechall.net/stegano
- 下一篇: 【高德地图开发3】---地图显示