我用了代理 为什么点击事件没作用?
#import
#import "AFNetWorkingTool.h"
@protocol FristSectionCollectionViewCellDelegate
@required
-(void)choseTerm:(UIButton *)button;
-(void)changeButtonBackgroundColor:(UIButton *)button;
@end
@interface FristSectionCollectionViewCell : UICollectionViewCell
@property(nonatomic,strong)UIButton *eight;
@property(nonatomic,assign)id delegate;
-(void)eight_btn_click:(UIButton *)btn;
@end
#import "FristSectionCollectionViewCell.h"
@implementation FristSectionCollectionViewCell
-(id)initWithFrame:(CGRect)frame{
for (int i = 0; i <8; i ++) {
_eight_btn = [UIButton buttonWithType:UIButtonTypeCustom];
_eight_btn.tag = i;
_eight_btn.frame = CGRectMake(坐标);
[self.contentView addSubview:_eight_btn];
[self.eight_btn addTarget:self action:@selector(eight_btn_click:) forControlEvents:UIControlEventTouchUpInside];
}
}
-(void)eight_btn_click:(UIButton *)btn{
if ([_delegate respondsToSelector:@selector(choseTerm:)]) {
[_delegate choseTerm:btn];
}
}
#import "MainViewController.h"
@interface MainViewController ()
-(void)choseTerm:(UIButton *)button{
NSLog(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< %ld",(long)button.tag);
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
cell的初始化通常不用这个,用了这个不调父类