zoukankan      html  css  js  c++  java
  • IOS--在cell里面用代理实现和block一样的功能

    1. ....cell.h

    @class HMDownloadTableViewCell;
    
    @protocol HMDownloadTableViewCellDegate <NSObject>
    
    - (void)downloadTableViewCellNeedDelete:(HMDownloadTableViewCell *)cell;
    
    @end
    
    @interface HMDownloadTableViewCell : UITableViewCell
    @property (nonatomic, weak) id<HMDownloadTableViewCellDegate> delegate;
    @property (strong, nonatomic)  UIButton *deleteBtn;                     //删除按钮
    @end

    2.   ...cell.m

    //触发,这里是通过cell里面的按钮来触发的
    - (void)deleteBtnClick:(id)sender
    {
        if ([self.delegate respondsToSelector:@selector(downloadTableViewCellNeedDelete:)]) {
            [self.delegate downloadTableViewCellNeedDelete:self];
        }
    }

    3.  ...tableView.m

    <UITableViewDelegate, UITableViewDataSource, HMDownloadTableViewCellDegate>
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      .....
      cell.delegate = self;    
       ....
    }
    
    #pragma mark - HMDownloadTableViewCellDegate
    - (void)downloadTableViewCellNeedDelete:(HMDownloadTableViewCell *)cell {
        NSLog(@"删除cell的书籍名字%@",cell.titleLabel.text);
    }
  • 相关阅读:
    JS开发技巧
    Git push 常见用法
    关闭浏览器标签
    vue 样式穿透 watch深度监听
    Git Commit Template 提交模板
    常用git stash命令:
    Windows下安装及使用NVM
    JS正则表达式
    js转码
    多行文本溢出显示省略号(…)全攻略
  • 原文地址:https://www.cnblogs.com/qiyiyifan/p/7305531.html
Copyright © 2011-2022 走看看