Swift: NotificationCenter 用法 --- swift3.0
2017-06-30 15:19
375 查看
//
// 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.
}
}
// 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 3.0 按钮的用法(UIButton)
- iOS -Swift 3.0 -Array(数组与可变数组相关属性及用法)
- Swift3.0——Swift中下划线的妙用,_的用法
- iOS -Swift 3.0 -for(循环语句用法)
- iOS -Swift 3.0 -String(字符串常规用法)
- 十 Swift3.0之 if 用法
- 十一 Swift3.0之 while 用法
- 十七 Swift3.0之 Switch用法
- Swift 3.0之后的Array用法记录以及循环遍历知识点
- IOS Swift3.0 获取导航栏跟状态栏的高度
- Swift3.0获取APP版本号,提示用户升级
- swift 3.0 冒泡排序,插入排序,选择排序,快速排序
- FMDB的基本使用和解析(Swift3.0)
- Swift3.0基本语法01
- Swift3.0 二维码扫描
- Swift 3.0 iOS 如何绘制 1px 宽的描边
- Swift3.0语言教程获取C字符串
- Swift - 进度条(UIProgressView)的用法
- Swift - 3.0之GCD学习
- Swift 数组详细用法