美文网首页
Mac Dev Part 7 - Notification

Mac Dev Part 7 - Notification

作者: 遇见Miu | 来源:发表于2019-03-07 17:30 被阅读0次

    生活不易

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

    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

    相关文章

      网友评论

          本文标题:Mac Dev Part 7 - Notification

          本文链接:https://www.haomeiwen.com/subject/rgrhpqtx.html