亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在SWIFT中實例化并呈現viewController

在SWIFT中實例化并呈現viewController

至尊寶的傳說 2019-07-08 16:31:17
在SWIFT中實例化并呈現viewController發行我開始看新的Swift在……上面Xcode 6,我嘗試了一些演示項目和教程?,F在我被困在:實例化,然后呈現viewController從一個特定的故事板目標-C溶液UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"myStoryboardName" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"myVCID"]; [self presentViewController:vc animated:YES completion:nil];如何在SWIFT上實現這一點?
查看完整描述

3 回答

?
慕森王

TA貢獻1777條經驗 獲得超3個贊

這都是新語法的問題,功能沒有改變:

// Swift 3.0let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)let controller = storyboard.instantiateViewController(w
ithIdentifier: "someViewController")self.present(controller, animated: true, completion: nil)

如果你有問題init(coder:),請參閱EridB回答.


查看完整回答
反對 回復 2019-07-08
?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

實例化UIViewController并且有例外:

致命錯誤:類使用未實現的初始化器‘init(編碼器:)’

快速提示:

手動實現required init?(coder aDecoder: NSCoder)在你的目的地UIViewController你想要實例化

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)}

如果您需要更多的描述,請參考我的回答。這里


查看完整回答
反對 回復 2019-07-08
?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

這個鏈接有兩個實現:

斯威夫特

let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController") 
as UIViewControllerself.presentViewController(viewController, animated: false, completion: nil)

目標C

UIViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"
ViewController"];

此鏈接具有在同一情節提要中啟動視圖控制器的代碼。

/*
 Helper to Switch the View based on StoryBoard
 @param StoryBoard ID  as String
*/func switchToViewController(identifier: String) {
    let viewController = self.storyboard?.instantiateViewControllerWithIdentifier(identifier) as! UIViewController
    self.navigationController?.setViewControllers([viewController], animated: false)}


查看完整回答
反對 回復 2019-07-08
  • 3 回答
  • 0 關注
  • 1217 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號