我想利用這個我函數內部函數運行之後呈現一個視圖控制器的功能裏面,所以包括這裏面使用presentviewcontroller迅速
let window = UIWindow()
let rootViewController = window.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("EmployeeTBCIdentifier")
rootViewController?.presentViewController(setViewController, animated: true, completion: nil)
它沒有做任何事情,它的工作原理,如果我用它裏面viewDidLoad中()
這裏的主要思想,並且有可能根據這個例子使用落成,
func logInType(completion(Void1, Void2)->()) {
if login == employer{
void1
}else if login == employee{
void2
}
}
使用我想retur函數時n
func logInType{(void1, void2) -> void in
void1 = self.presentview //I want to push view to another if this code executed
void2 = self.presentview //same idea
}
已更新:代碼正在工作,但未推送到已標識的視圖控制器。
dispatch_async(dispatch_get_main_queue()){
let window = UIWindow()
let rootViewController = window.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("EmployeeTBCIdentifier")
rootViewController?.presentViewController(setViewController, animated: true, completion: nil)
}
您可以在您嘗試呈現viewController的地方添加整個函數嗎? – Karlos