码迷,mamicode.com
首页 > 其他好文 > 详细

Notification的简单使用

时间:2016-08-31 11:50:08      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

//

//  ViewController.swift

//  xcode8Beta测试

//

//  Created by zhangxu on 16/8/31.

//  Copyright © 2016年 zhangxu. All rights reserved.

//

 

import UIKit

 

class ViewController: UIViewController {

    

    let SendNotification = NSNotification.Name.init(rawValue: "SendNotification");

 

    override func viewDidLoad() {

        super.viewDidLoad()

        

        // 添加通知

        NotificationCenter.default.addObserver(self, selector: #selector(receivedNotification(notification:)), name: SendNotification, object: nil);

        

        // Do any additional setup after loading the view, typically from a nib.

    }

    

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        

        // 发送通知

        NotificationCenter.default.post(name: SendNotification, object: nil, userInfo: ["SendNotification": "发送通知"]);

        

    }

    

    // MARK: - 收到通知

    func receivedNotification(notification: NSNotification) -> Void {

        

        let string = notification.userInfo!["SendNotification"];

        print(string ?? "");

   }

 

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

 

 

}

 

Notification的简单使用

标签:

原文地址:http://www.cnblogs.com/Brisy/p/5825125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!