【发布时间】:2020-06-28 21:29:41
【问题描述】:
我有一个按钮的代码,当单击该按钮时,它会将用户带到主页,这是我命名为“HomePageViewController”的 UIViewController,我还设置了如下所示的类: class set up.
按钮代码位于名为“SignInViewController”的第一个(初始控制器)UIViewController 中,当单击它时,我希望 HomePageViewController 替换 SignInViewController:
@IBAction func btnSignInPressed(_ sender: UIButton) {
// if true take to home page
DispatchQueue.main.async {
let home = self.storyboard?.instantiateViewController(identifier: "HomePageViewController") as!
HomePageViewController
// replace the homepage as the root page
let appDelegate = UIApplication.shared.delegate
appDelegate?.window??.rootViewController = home
}
}
但是,当我在刺激器中运行它时,当我单击它时,该按钮不会做任何事情。请注意,我使用的是 Tab Bar Controller,所以我尝试将根设置为 UIBarController,但这也不起作用。
【问题讨论】:
-
为什么要将此块执行到
DispatchQueue.main.async中?
标签: swift xcode uiviewcontroller