如何在iOS Swift 3中以编程方式推送和呈现给UIViewController而不使用segue [英] How to push and present to UIViewController programmatically without segue in iOS Swift 3
本文介绍了如何在iOS Swift 3中以编程方式推送和呈现给UIViewController而不使用segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 iOS SHOW 和 MODALLY > 目标C 。
现在想了解Swift 3.
I am using this code for push SHOW and MODALLY programmatically in iOS Objective C.
And now wanna know about Swift 3.
NewsDetailsViewController *vc = instantiateViewControllerWithIdentifier:@"NewsDetailsVCID"];
vc.newsObj = newsObj;
//--this(SHOW)
[self.navigationController pushViewController:vc animated:YES];
//-- or this(MODAL)
[self presentViewController:vc animated:YES completion:nil];
谢谢。
推荐答案
推送
喜欢
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("NewsDetailsVCID") as NewsDetailsViewController
vc.newsObj = newsObj
navigationController?.pushViewController(vc,
animated: true)
或更安全
if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "NewsDetailsVCID") as? NewsDetailsViewController {
viewController.newsObj = newsObj
if let navigator = navigationController {
navigator.pushViewController(viewController, animated: true)
}
}
现在
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("NewsDetailsVCID") as! NewsDetailsViewController
vc.newsObj = newsObj
present(vc!, animated: true, completion: nil)
或更安全
if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "NewsDetailsVCID") as? NewsDetailsViewController
{
vc.newsObj = newsObj
present(vc, animated: true, completion: nil)
}
这篇关于如何在iOS Swift 3中以编程方式推送和呈现给UIViewController而不使用segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文