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

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

Xcode5中如何切換Storyboards為xib

2019-11-14 20:40:39
字體:
來源:轉載
供稿:網友

在Xcode5中,當創建一個帶View的iphone項目時,默認必須使用Storyboards,不再支持切換xib的checkbox。本文講解如何手動切換到使用xib來布局。

1,把Main.storyboard從項目中移除

 

2,添加xib文件到項目中。添加一個新文件,選擇View,命名和*ViewContorller相同。

 

3,把Main storyboard對應的項從plist文件中移除

 

4,在*AppDelegate中添加類似代碼

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;     // Override point for customization after application launch.     TestViewController *test = [[TestViewController alloc]     initWithNibName:@"TestViewController" bundle:nil];     UINavigationController *nav = [[UINavigationController alloc]  initWithRootViewController:test];     self.window.rootViewController = nav;     [self.window makeKeyAndVisible];     return YES;}

如果ARC關閉的話,以上代碼需要手動添加autorelease,這里不詳述了。

 

5,可選:關閉ARC。 在項目的build setting中,找到 Objective-C Automatic Reference Counting, 設置為No

image

 

6,把xib關聯到對應的ViewController上,否則會報如下錯誤

NibName[2203:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "loc" nib but the view outlet was not set.'

 

步驟(參考自 loaded some nib but the view outlet was not set):

1). 點擊我們要加載的 xib 文件

2). 在右邊選中 File's Owner

image

3). 在 File's Owner 的 image 選項卡的“Custom Class” 屬性設置中,將 Class 的值改成對應的 VC, 這里改成 UIViewController,

image

image

4). 這時候,在File's Owner 的  image選項卡中, 就 會出現“待連接設置” 的 view 屬性, 也即我們的編譯器 告訴我們的 the view outlet was not set  中的 view。當 File's Owner 的 class 為 NSObject 時候,是沒有 view 屬性的。

image

連接 view 屬性(把連線拖動到xib設計器中進行連接),

image

 

參考:

http://m.survivalescaperooms.com/TivonStone/archive/2012/04/20/2460116.html

http://stackoverflow.com/questions/17234172/xcode-5-without-storyboard-and-arc


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙海市| 普兰县| 镇宁| 文昌市| 双城市| 昂仁县| 周至县| 亳州市| 门头沟区| 定安县| 聂荣县| 搜索| 牙克石市| 宜春市| 依兰县| 蓬安县| 郧西县| 西平县| 闽清县| 体育| 易门县| 渑池县| 林西县| 道孚县| 三江| 安徽省| 大同县| 耒阳市| 威信县| 沙洋县| 西宁市| 共和县| 通州区| 电白县| 德州市| 公安县| 沧源| 台江县| 德安县| 大英县| 武穴市|