我正在使用Swift 4,我有以下代码:
let signInButton: UIButton = {
let button = UIButton()
button.setTitle("Sign In", for: .normal)
button.setTitleColor(.white, for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = UIColor(white: 0.4, alpha: 0.4)
button.titleLabel!.font = .systemFont(ofSize: 20)
button.addTarget(self, action: #selector(handlesignIn), for: .touchUpInside)
return button
}()
@objc func handlesignIn() {
dismiss(animated: true, completion: {
print("a")
})
self.navigationController?.pushViewController(Main(), animated: true)
}
编写此代码的控制器为UIViewController
,Main
为UITabController
。这段代码没有给我任何错误,但它也没有用。它甚至不打印"a"
。那是为什么?
的AppDelegate:
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = SignIn()