Swift: NotificationCenter 用法 --- swift3.0

Swift: NotificationCenter 用法 --- swift3.0,第1张

概述// //  ViewController.swift //  TestNotify // //  Created by huangtao on 2017/6/30. //  Copyright © 2017年 huangtao. All rights reserved. // Swift 3.0 import UIKit class ViewController: UIViewControlle

//

// VIEwController.swift

// TestNotify

// Created by huangtao on 2017/6/30.

// copyright © 2017 huangtao. All rights reserved.

// Swift 3.0


import UIKit


class VIEwController: UIVIEwController {


@IBOutlet weak var btnSend: UIbutton!

overrIDe func vIEwDIDLoad() {

super.vIEwDIDLoad()

btnSend.addTarget(self,action: #selector(btnSendFun(_:)),for: UIControlEvents.touchUpInsIDe)

NotificationCenter.default.addobserver(self,selector: #selector(notifyFun(note:)),name: NSNotification.name(rawValue:"test"),object: nil);

}

func notifyFun(note:Notification){

print(" note:\(note.object as! String)")

}


func btnSendFun(_ btn:UIbutton) {

NotificationCenter.default.post(name: NSNotification.name(rawValue:"test"),object: "111111");

}

deinit {

NotificationCenter.default.removeObserver(self);

}

overrIDe func dIDReceiveMemoryWarning() {

super.dIDReceiveMemoryWarning()

// dispose of any resources that can be recreated.

}



}

总结

以上是内存溢出为你收集整理的Swift: NotificationCenter 用法 --- swift3.0全部内容,希望文章能够帮你解决Swift: NotificationCenter 用法 --- swift3.0所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1061466.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存