我需要通过从另一个视图调用它来创建这个视图,我需要能够在没有 appdelegate 的情况下创建视图。我需要这方面的帮助。谢谢
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SampleData.createSampleData()
let graph = Graph()
let search = Search<Entity>(graph: graph).for(types: "Category")
var viewControllers = [PostsViewController]()
for category in search.sync() {
if let name = category["name"] as? String {
viewControllers.append(PostsViewController(category: name))
}
}
let pageTabBarController = AppPageTabBarController(viewControllers: viewControllers)
let toolbarController = AppToolbarController(rootViewController: pageTabBarController)
let menuController = AppMenuController(rootViewController: toolbarController)
let leftViewController = LeftViewController()
let navigationDrawerController = NavigationDrawerController(rootViewController: menuController,
leftViewController: leftViewController
)
window = UIWindow(frame: Screen.bounds)
window!.rootViewController = navigationDrawerController
window!.makeKeyAndVisible()
return true
}
**这是我的代码,一直崩溃**
导入 UIKit 导入 材质 导入 Graph
类视图控制器:PageTabBarController {
var window: UIWindow?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
open override func prepare() {
super.prepare()
SampleData.createSampleData()
let graph = Graph()
let search = Search<Entity>(graph: graph).for(types: "Category")
var viewControllers = [PostsViewController]()
for category in search.sync() {
if let name = category["name"] as? String {
viewControllers.append(PostsViewController(category: name))
}
}
let pageTabBarController = AppPageTabBarController(viewControllers: viewControllers)
let toolbarController = AppToolbarController(rootViewController: pageTabBarController)
let menuController = AppMenuController(rootViewController: toolbarController)
let leftViewController = LeftViewController()
let navigationDrawerController = NavigationDrawerController(rootViewController: menuController,
leftViewController: leftViewController
)
window = UIWindow(frame: Screen.bounds)
window!.rootViewController = navigationDrawerController
window!.makeKeyAndVisible()
}
} 扩展 ViewController: PageTabBarControllerDelegate { func pageTabBarController(_ pageTabBarController: PageTabBarController, didTransitionTo viewController: UIViewController) {
}
}