zoukankan      html  css  js  c++  java
  • Swift代理的使用

    Swift代理的使用

    协议规定了用来实现某一特定功能所必需的方法和属性。

    任意能够满足协议要求的类型被称为遵循(conform)这个协议。

    类,结构体或枚举类型都可以遵循协议,并提供具体实现来完成协议定义的方法和功能。

    1、申明代理

    // 协议内容

    @objc protocol TLSelectViewDelegate{

        

        func TLSelectViewDidSelected()  //必须方法

        @objc optional func TLSelectViewQuit() //可选方法

    }

     

     

    2、定义一个代理属性

    weak var  delegate: TLSelectViewDelegate?

     

     

    3、使用者,首先加上

    class TaskListViewController: UIViewController,TLSelectViewDelegate {

     

    4、设置代理和实现

    let cell: TLTaskListCell = tableView.dequeueReusableCell(withIdentifier: "TLTaskListCell") as! TLTaskListCell

    cell.selectionStyle = .none;

    cell.delegate = self

     

    5、在需要的地方直接调用

    if let delegateOK = self.delegate{

       delegateOK.TLSelectViewDidSelected()

    }

  • 相关阅读:
    C#的几种下载文件方法
    分享下常用的网站
    C#操作XML文件
    MySQL截取字符串函数方法
    NLog使用方法
    弹出div提示框,背景变黑
    有关URL编码问题
    javascript 压缩工具
    [C#][Windows API] 常用Windows原生方法整理(Windows API) (不定期更新: 06/16)【转】
    An Introduction to IDS
  • 原文地址:https://www.cnblogs.com/jukaiit/p/9110375.html
Copyright © 2011-2022 走看看