ios - swift 类和 Objective -c Viewcontrollers 之间的通知中心网络

标签 ios objective-c iphone swift

在我的 Objective-C 类中,我添加了以下代码

[[NSNotificationCenter defaultCenter] postNotificationName:@"Notify" object:nil];

在我的 Swift 类中,我添加了以下代码

NotificationCenter.defaultCenter().addObserver(self, selector:(DataProcessingMethod), name:@"" , object: nil)

但不幸的是不起作用,代码有什么问题?

最佳答案

应该是这样的:

NotificationCenter.default.addObserver(self, selector: #selector(DataProcessingMethod), name: NSNotification.Name(rawValue: "Notify"), object: nil)

关于ios - swift 类和 Objective -c Viewcontrollers 之间的通知中心网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42415872/

相关文章:

javascript - iOS - 在 UIWebView 中嵌入 Facebook 视频

ios - 转换纹理中的 UIImage

ios - Xcode7 核心绘图错误 : CPTPlot, NSString

ios - 使用 NSOutputStream 发送字节数组

ios - Apple Watch 是否可以直接从 Web 服务器获取数据,而无需 iPhone 作为中介?

ios - XMPPRoster 不会将新好友发布到 XMPP 服务器

objective-c - 如何使 UIAlertView 不根据 buttonIndex 关闭

ios - SQLITE 数据库与 iOS 和 ICloud

ios - 为什么这个带有 ARC 的简单应用程序会泄漏?

ios - 在导航 Controller 中设置后退按钮的操作