我已经创建了一个基本的单视图应用程序。现在使用Xcode 11。我总是以编程方式构建应用程序,因为我开始的教程从未使用过界面构建器。由于某种原因,pushViewController无法正常工作。似乎在我使用Xcode 10构建的其他项目中也能正常工作。
应用内委托
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.makeKeyAndVisible()
let nc = UINavigationController(rootViewController: ViewController())
window?.rootViewController = nc
return true
}
在我的viewController中
@objc func handleChat(){
print("Chat pressed")
navigationController?.pushViewController(InboxViewController(), animated: true)
}
答案 0 :(得分:0)
AppDelegate.swift
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let VC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as? ViewController
var Nav: UINavigationController? = nil
if let VC = VC {
Nav = UINavigationController(rootViewController: VC)
}
window?.rootViewController = Nav
return true
}
删除SceneDelegate.swift
转到Info.plist
删除应用场景清单
这对我有用。