gpt4 book ai didi

ios - 如何在 iOS Swift 3 中以编程方式推送和呈现给 UIViewController 而无需 segue

转载 作者:IT王子 更新时间:2023-10-29 05:08:41 25 4
gpt4 key购买 nike

我正在使用此代码在 iOS 中以编程方式推送 SHOWMODALLY> objective-c
现在想了解 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 - 如何在 iOS Swift 3 中以编程方式推送和呈现给 UIViewController 而无需 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39929592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com