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()

    }

  • 相关阅读:
    javascript小白学习指南1---0
    C++学习笔记11-面向对象2
    cocos2d-x 3.0正式版 vs2013配置
    awk命令拷屏
    java实现第四届蓝桥杯空白格式化
    java实现第四届蓝桥杯空白格式化
    java实现第四届蓝桥杯空白格式化
    java实现第四届蓝桥杯空白格式化
    java实现第四届蓝桥杯空白格式化
    java实现第四届蓝桥杯危险系数
  • 原文地址:https://www.cnblogs.com/jukaiit/p/9110375.html
Copyright © 2011-2022 走看看