Re: [請益] 如何push Framework裡的viewcontroller
※ 引述《fbifxxkma (超棒Der)》之銘言:
: 我自製一個framework
: 裡面有一個viewcontroller.swift
: 還有他的storyboard 並設定他倆的對應關係
: 然後打包成framework
: ------
: 接著 我新開一個 project
: import 剛剛那個自製的 framework
: 我要如何push 出 framework裡面的畫面(viewcontroller)呢?
swift的我是不會啦
但是objective-c的我實作過 可以給你拋磚引玉一下
首先找到整個 App 的 UIWondow
大概像這樣,這樣你就可以在framework裡 去的 實際runtime時的UIWindow
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
然後從 Bundle 裡尋找需要的資源,大概像這樣
這個bundle你要自己包,要包的東西大概就圖片啊 Storyboard之類的
NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:@"YourBundle.bundle"];
接著你就可以從Bundle讀到你的StoryBoard了
yourViewController = [[UIStoryboard storyboardWithName:@"YourStoryBoardName" bundle:[NSBundle bundleWithPath:frameworkBundlePath]] instantiateViewControllerWithIdentifier:@"Nav"];
最後你就可以從UIWindow拿到 rootviewcontroller 有兩個 viewController基本上就可以為所欲為了
這是一個簡單的範例
[keyWindow.rootViewController.view addSubview: yourViewController.view];
大概是這樣啦
-----
Sent from JPTT on my iPhone
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.42.120.124
※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1547928115.A.871.html
→
01/20 04:03,
6年前
, 1F
01/20 04:03, 1F
→
01/20 04:49,
6年前
, 2F
01/20 04:49, 2F
→
01/20 04:49,
6年前
, 3F
01/20 04:49, 3F
→
01/21 03:09,
6年前
, 4F
01/21 03:09, 4F
→
01/21 03:09,
6年前
, 5F
01/21 03:09, 5F
→
01/21 03:09,
6年前
, 6F
01/21 03:09, 6F
→
01/21 03:09,
6年前
, 7F
01/21 03:09, 7F
→
01/21 03:09,
6年前
, 8F
01/21 03:09, 8F
→
01/21 03:09,
6年前
, 9F
01/21 03:09, 9F
→
01/21 03:09,
6年前
, 10F
01/21 03:09, 10F
→
01/21 03:10,
6年前
, 11F
01/21 03:10, 11F
→
01/21 03:10,
6年前
, 12F
01/21 03:10, 12F
推
01/24 17:04,
6年前
, 13F
01/24 17:04, 13F
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章