一、cell上按钮的展开闭合
1.声明个BOOL数组
{
BOOL isUnfolds[500];
}
2.点击回调方法,对BOOL数组中当前index进行取反,刷新当前index的行
cell.unfoldBtnClickBlock = ^(UIButton *unfoldBtn) {
isUnfolds[indexPath.row] = !isUnfolds[indexPath.row];
NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
NSLog(@"第几行%ld",indexPath.row);
[self.seleTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath1, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
};
3.cellForRowAtIndexPath方法中写入BOOL数组index判断方法,并进行 视图的remake
// 展开、闭合
cell.foldBtn.tag = indexPath.row;
if (isUnfolds[indexPath.row]) {
cell.foldBtn.selected = YES;
[cell.topBGView remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(cell.top).offset(10);
make.left.equalTo(cell.left).offset(14);
make.width.equalTo(SelfWidth-60);
make.height.equalTo(90+90);
}];
cell.bottomBGView.hidden = NO;
} else {
cell.foldBtn.selected = NO;
[cell.topBGView remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(cell.top).offset(10);
make.left.equalTo(cell.left).offset(14);
make.width.equalTo(SelfWidth-60);
make.height.equalTo(90);
}];
cell.bottomBGView.hidden = YES;
}
二、cell上的按钮单选
1. 声明属性
@property (nonatomic , strong) NSIndexPath *lastIndexPath;
2.cellForRowAtIndexPath 方法中实现代码
NSInteger row = [indexPath row];
NSInteger oldRow = [_lastIndexPath row];
if (row == oldRow && _lastIndexPath) {
cell.defaultLab.text = @"设为默认地址";
cell.defaultLab.textColor = HEXCOLOR(0xff4e11);
cell.gouImageView.image = [MSUPathTools showImageWithContentOfFileByName:@"WechatIMG169"];
}
3.didSelectRowAtIndexPath 方法中实现代码
NSInteger newRow = [indexPath row];
NSInteger oldRow = self.lastIndexPath?[self.lastIndexPath row]:-1;
if (newRow != oldRow) {
MSUManageAddressTableCell *NewCell = [tableView cellForRowAtIndexPath:indexPath];
NewCell.defaultLab.text = @"设为默认地址";
NewCell.defaultLab.textColor = HEXCOLOR(0xff4e11);
NewCell.gouImageView.image = [MSUPathTools showImageWithContentOfFileByName:@"WechatIMG169"];
MSUManageAddressTableCell *oldCell = [tableView cellForRowAtIndexPath:_lastIndexPath];
oldCell.defaultLab.text = @"默认地址";
oldCell.defaultLab.textColor = HEXCOLOR(0x333333);
oldCell.gouImageView.image = [MSUPathTools showImageWithContentOfFileByName:@"WechatIMG217"];
self.lastIndexPath = indexPath;
}
网友评论