当前位置: 首页 > news >正文

IOS 自定义代理协议Delegate

QuestionViewCell.h文件代码,定义代理协议

@protocol QuestionViewCellDelegate <NSObject>- (void)cellIsOpenDidChangeAtIndexPath:(NSIndexPath *)indexPath;@end@interface QuestionViewCell : UITableViewCell@property (nonatomic, weak) id<QuestionViewCellDelegate> delegate;@end

QuestionViewCell.m文件调用代理代码


#import "QuestionViewCell.h"@interface QuestionViewCell ()@end@implementation QuestionViewCell- (void)awakeFromNib {[super awakeFromNib];[FontSizeUtil setupWidgets:@[self.titleLabel, self.contentLabel]pingfangWithFontSizes:@[@12, @11]];
}- (IBAction)openClickAction:(id)sender {if (self.delegate && [self.delegate respondsToSelector:@selector(cellIsOpenDidChangeAtIndexPath:)]) {[self.delegate cellIsOpenDidChangeAtIndexPath:self.indexPath];}
}@end

UITableView设置代理对象

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {、QuestionViewCell *cell = [tableView dequeue:QuestionViewCell.class forIndexPath:indexPath];cell.indexPath = indexPath;cell.delegate = self;return cell;
}

ViewController.m 委托者实现代理协议

@interface TestViewController ()
<QuestionViewCellDelegate,
UITableViewDelegate,
UITableViewDataSource>
@end@implementation TestViewController#pragma mark - QuestionViewCellDelegate- (void)cellIsOpenDidChangeAtIndexPath:(NSIndexPath *)indexPath {//刷新Row行[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}@end

http://www.lryc.cn/news/527049.html

相关文章:

  • 消息队列篇--扩展篇--码表及编码解码(理解字符字节和二进制,了解ASCII和Unicode,了解UTF-8和UTF-16,了解字符和二进制等具体转化过程等)
  • 2024年度总结——理想的风,吹进现实
  • 代码工艺:实践 Spring Boot TDD 测试驱动开发
  • 深度学习|表示学习|卷积神经网络|通道 channel 是什么?|05
  • PCDN的虚拟机与云主机区别
  • 计算机网络 (57)改进“尽最大努力交付”的服务
  • Redis 详解
  • 如何解压rar格式文件?8种方法(Win/Mac/手机/网页端)
  • 网络仿真工具Core环境搭建
  • Coze插件开发之基于已有服务创建并上架到扣子商店
  • ORACLE-主备备-Failover
  • wampserver + phpstrom 调试配置
  • Java Web-Cookie与Session
  • Couchbase UI: Dashboard
  • 每日 Java 面试题分享【第 13 天】
  • 探究 Facebook 隐私安全发展方向,未来走向何方?
  • 第三十一周学习周报
  • 白嫖一个可以公网访问、带评论和图床的博客系统
  • 定时器、计数器
  • Ubuntu Server连接wifi
  • 关于MySQL InnoDB存储引擎的一些认识
  • 深入剖析SpringBoot启动机制:run()方法详尽解读
  • Nginx中部署多个前端项目
  • 1688寻源通:赋能跨境贸易的高效业务平台
  • JVM深入学习(一)
  • Qt Creator 15.0.0如何更换主题和字体
  • “大模型横扫千军”背后的大数据挖掘--浅谈MapReduce
  • shallowRef和shallowReactive的用法以及使用场景和ref和reactive的区别
  • maven、npm、pip、yum官方镜像修改文档
  • HTML5+SVG+CSS3实现雪中点亮的圣诞树动画效果源码