第一步:根据选中的数据改变图片状态,这里是通过获取数据显示不同状态按钮的
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *ID = @"SsLocationCell";
SsLocationCell *cell =[tableView dequeueReusableCellWithIdentifier:ID];
if (cell ==nil) {
cell = [SsLocationCell xibInitWithNib];
}
if (_selectIndex ==indexPath) {
cell.ChooseAnimation.image =[UIImage imageNamed:@"ss_mapon"];
}else{
cell.ChooseAnimation.image =[UIImage imageNamed:@"ss_mapoff"];
}
return cell;
}
第二步:实时更新数据UI的点中状态
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//如果是之前选中的,则取消选择
SsLocationCell *celled = (SsLocationCell *)[tableView cellForRowAtIndexPath:_selectIndex];
celled.ChooseAnimation.image =[UIImage imageNamed:@"ss_mapoff"];
//记录当前选中的位置
_selectIndex = indexPath;
//当前选择的打勾
SsLocationCell *cell = (SsLocationCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.ChooseAnimation.image =[UIImage imageNamed:@"ss_mapon"];
}
网友评论