搜索
您的当前位置:首页正文

Mac Dev Part 7 - Notification

来源:二三娱乐

生活不易

但是不能让它慢慢磨掉你向往美好的蓝图

1.NSNotification

和iOS上的通知没有什么区别,所以在昨天的containerView上进行修改

RightViewController.swift

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "click"), object: self)

LeftViewController.swift

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

可以在Constants.swift中定义通知名

enum CVNotifications : String {
    case Click = "click"
    case Press = "press"
    case Tap = "Tap"
}

调用也是很方便的

LeftViewController.swift

NotificationCenter.default.post(name: NSNotification.Name(rawValue: CVNotifications.Click.rawValue), object: self)

效果图:


接收通知.gif
Top