我正试图通过自定义类从一个按钮转到另一个storyBoard中的新viewController。这就是自定义类的外观。
import UIKit
import Foundation
class NavigationController{
static func segueToNextViewController(#storyboardName: String){
var eventsBoard: UIStoryboard = UIStoryboard(name: storyboardName, bundle: NSBundle.mainBundle())
var nextViewController = eventsBoard.instantiateInitialViewController() as! UIViewController
self.presentViewController(nextViewController, animated: true, completion: nil)
}
}
但我有一个错误说明: 'NavigationController.Type'在此行上没有名为'presentViewController'的成员self.presentViewController(nextViewController,animated:true,completion:nil)
任何帮助都将非常感激
答案 0 :(得分:0)
试试这个,
import UIKit
import Foundation
class NavigationController{
func segueToNextViewController(storyboardName: String){
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("#YourViewControllerName") as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)
}
}
*确保在View Controller的故事板ID中添加一个名称并将相同的名称粘贴到代码中的#YourViewControllerName
答案 1 :(得分:0)
排序。只需要创建UIViewController的扩展并将此代码放入其中。