UIButton * checkBox=[UIButton buttonWithType:UIButtonTypeCustom];
objc_setAssociatedObject(checkBox, "indexPath", indexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC);获取参数
UIButton *tappedButton = (UIButton*)sender;
NSIndexPath* indexPath = objc_getAssociatedObject(tappedButton, "indexPath");需要头文件
#import <objc/runtime.h>

本文介绍如何使用Objective-C为UIButton设置indexPath作为关联对象,并从UIButton中检索该indexPath。需要引入objc/runtime.h头文件来实现objc_setAssociatedObject和objc_getAssociatedObject函数。
1万+

被折叠的 条评论
为什么被折叠?



