【发布时间】:2015-10-06 22:17:23
【问题描述】:
我通过 NSNotification 从 ViewController 1 向 ViewController 3 和从 ViewController 2 向 ViewController 3 发送数据。
NSNotificationCenter.defaultCenter().postNotificationName("retirementChange", object: retirementText?.text)
当我将数据从 NSNotification 设置到 ViewController 3 中的变量时,我打印来自 ViewController 3 的数据。我将变量 age 设置为通知对象。
NSNotificationCenter.defaultCenter().addObserver(self, selector: "setRetirementAge:", name: "retirementChange", object: nil)
func setRetirementAge(notification: NSNotification){
age = notification.object!
print(age)
}
当时它在控制台中打印得很好,但是当我尝试在页面加载后使用值年龄时,它是空白的。
任何帮助将不胜感激。谢谢
【问题讨论】:
-
你为什么使用 NSNotification 而不仅仅是通过 ViewControllers 中的变量传递数据?
-
我有静态表格单元格
-
为什么将数据存储在视图控制器而不是数据模型中。无论如何,
age是如何声明的,何时何地。 -
赞夫赞。而且我不明白为什么即使你有静态单元格也不能用变量传递数据,它们之间没有关系......
-
在ViewController 3中声明
var age: AnyObject = ""
标签: ios iphone swift uiviewcontroller notifications