我在ViewController中有一个细分控件和一个容器。在容器中是一个PageViewController。如果单击细分控件中的一项,则更改了表“用户”的值“活动”。(sqlite)表“用户”:
username text, active bool
user1, false
user2,true
因此,如果您在细分控件中单击user1,则该表将更改为
username text, active bool
user1, true
user2,false
有没有一种方法可以使PageViewController中的所有ViewController识别数据库中的更改,并用新用户重新加载其数据。如果这不可能,那么最好的方法是什么?
亲切的问候
如果我理解正确,则希望在其他视图控制器中更改分段控件的值时通知一些视图控制器。
在这种情况下,您可以使用NSNotificationCenter。
NsNotificationCenter
向其观察者发送通知。当观察者收到通知时,您可以使其执行某些操作。
例子:
NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(aMethod(_:)), name:"NotificationIdentifier", object: nil)
func aMethod(notification: NSNotification){
// Do stuff here
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句