//选择转账用户对勾
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger newRow = [indexPathrow];
NSInteger oldRow = (_lastPath ==nil)?[_lastPathrow]:-1;
if (newRow != oldRow) {
UITableViewCell *newCell = [tableViewcellForRowAtIndexPath:indexPath];
newCell.accessoryType =UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableViewcellForRowAtIndexPath:_lastPath];
oldCell.accessoryType =UITableViewCellAccessoryNone;
_lastPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPathanimated:YES];
_selectSourceM = _dataSourceM[newRow];
}
下面是自定义的单选
创建Model 设置个BOOL值
#import <Foundation/Foundation.h>
@interface Model : NSObject
@property(nonatomic, assign) BOOL isSelected;
@end
cell.h
#import <UIKit/UIKit.h>
@class Model;
@interface LYTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *btn;
@property(assign, nonatomic)NSInteger clickCount;
- (void)cellWithData:(Model *)model;
自定义cell .m
- (void)cellWithData:(Model *)model {
if (model.isSelected) {
[self.btn setBackgroundImage:[UIImage imageNamed:@"选中"] forState:UIControlStateNormal];
} else {
[self.btn setBackgroundImage:[UIImage imageNamed:@"未选中"] forState:UIControlStateNormal];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
[cell.btn addTarget:self action:@selector(ClickBtn:) forControlEvents:UIControlEventTouchUpInside];
cell.btn.tag = indexPath.row;
Model *model =self.arrays[indexPath.row];
[cell cellWithData:model];
return cell;
}
-(void)ClickBtn:(UIButton *)btn
{
if (self.selectModel) {
self.selectModel.isSelected = !self.selectModel.isSelected;
}
Model *model = self.arrays[btn.tag];
if (!model.isSelected) {
model.isSelected = !model.isSelected;
self.selectModel = model;
}
[self.tableView reloadData];
}