gpt4 book ai didi

ios - 从另一个 View Controller 通知 View Controller

转载 作者:可可西里 更新时间:2023-11-01 00:21:36 27 4
gpt4 key购买 nike

我在 ViewController 中有一个 Segment Control 和一个 Container。在容器中是一个 PageViewController。如果您单击段控件中的其中一项,则表“用户”的值“事件”将更改。(sqlite)表“用户”:

username text, active bool
user1, false
user2,true

因此,如果您在 Segment Control 中单击 user1,表格将更改为

username text, active bool
user1, true
user2,false

有没有一种方法可以让 PageViewController 中的所有 ViewController 识别数据库中的更改并使用新用户重新加载它们的数据。如果这不可能,最好的方法是什么?

亲切的问候

最佳答案

如果我没理解错的话,您希望在更改另一个 View Controller 中的分段控件值时通知某些 View Controller 。

在这种情况下,您可以使用 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
}

关于ios - 从另一个 View Controller 通知 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38937371/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com