我正在使用此代码在 iOS* Objective C中 以 编程方式推送 SHOW 和 MODALLY 。 现在想了解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) }