尝试从Objective-C发送通知并在Swift中接收。 发件人或收件人没有错误,但在目标视图控制器中未调用函数。
视图控制器1:Objective-C
视图控制器1:Objective-C
[[NSNotificationCenter defaultCenter]
postNotificationName:@"notifyme"
object:self
userInfo:self.profile];
视图控制器 2:Swift
override func viewDidLoad() {
super.viewDidLoad()
print("view did load")
NSNotificationCenter.defaultCenter().addObserver(self, selector: "receiveNotification:", name: "notifyme", object: nil)
}
func receiveNotification(ns: NSNotification){
print("Received Notification")
}
receiveNotification
上方添加@objc注释。否则,你的代码看起来很好。 - hris.to