废话不说, 直接上代码。。。。。
@interface CJWPopCardListView ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, assign) NSIndexPath *selectedIndexPath;//定义选中的cell 的indexPath
@end
@implementation CJWPopCardListView
//cell复用里面
-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CJWCardTableViewCell *cell = (CJWCardTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CJWCardTableViewCell" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row == _bankListArray.count) {
cell.cardInfoLabel.text = @"使用其它银行卡";
cell.arrowImg.hidden = NO;
}else{
if (_bankListArray.count) {
cell.cardInfoLabel.text = [NSString stringWithFormat:@"%@",emptyString([[_bankListArray objectAtIndex:indexPath.row]objectForKey:@"bank_name"])];
}
cell.arrowImg.hidden = YES;
}
//重点在此
if ([self.selectedIndexPath isEqual:indexPath]){cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
} -
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == _bankListArray.count) {
NSLog(@"添加银行卡");
[self closeView];
}else{if (self.selectedIndexPath) { CJWCardTableViewCell *cell = [tableView cellForRowAtIndexPath:self.selectedIndexPath]; cell.accessoryType = UITableViewCellAccessoryNone; } CJWCardTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryCheckmark; self.selectedIndexPath = indexPath; NSDictionary *selDic = [_bankListArray objectAtIndex:indexPath.row]; NSLog(@"选中的银行卡信息:%@",selDic); if (_delegate && [_delegate respondsToSelector:@selector(selectedBankInfoDic:)]) { [_delegate selectedBankInfoDic:selDic]; } }
}
网友评论