我需要在控制器上设置一个属性,这是在应用程序委托中进行的设置。在上一个使用导航栏的任务中,此方法有效:
(我要设置属性的控制器不是根控制器,而是第三个选项卡,如果有帮助的话)
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
// Override point for customization after application launch.
// Create an ItemStore
let itemStore = ItemStore()
// Access the ItemsViewController and set its item store
let itemsController = window!.rootViewController as! ItemsViewController
itemsController.itemStore = itemStore
return true }
但是,创建类似的程序时,我需要使用选项卡栏,但无法使其正常工作并继续遇到上述错误, 让editcontroller = tabcontroller。 -线
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
// Override point for customization after application launch.
// Create an pindatabase
let pinDataBase = PinDatabase()
// Access the ContactsViewController and set its contact store
let tabController = window!.rootViewController as! UITabBarController
let editController = tabController.tabBar as! EditViewController
editController.pinDataBase = pinDataBase
return true
}
任何帮助将不胜感激