【发布时间】:2018-06-18 09:48:32
【问题描述】:
我想知道是否可以更改或修改对象,例如来自AppDelegate.swift 的另一个视图控制器的按钮。
这是我试图开始但不知何故卡住的。
func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if application.applicationState == .active {
if self.window?.rootViewController is homeViewController {
//modify a button exist in homeViewController
}
}
}
感谢任何帮助。提前致谢。
【问题讨论】:
-
理论上这是可能的,但它会破坏 MVC 模式 (developer.apple.com/library/content/documentation/General/…)。如果你将 rootViewController 转换为 homeViewController 你可以访问他的属性。
-
哦,我明白了..问题是我想根据收到的通知更新 homeViewController 中的按钮...那么,除了我有什么之外,还有其他选择吗? @lorenzoliveto
-
您可以使用答案中已发布的 NotificationCenter。
标签: ios swift uiviewcontroller appdelegate