我想通过方法来改变细胞的附属视图类型:didSelectRowAtIndexPath方法,即在选择行我想改变附属视图类型,我可以做这里面的那个方法?
Answers:
您可以像这样使用indexPath从didSelectRowAtIndexPath:方法获取单元格。
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[tableView reloadData]
?
存储选定的索引路径。例如:NSInteger selectedIndexPath; 然后按照以下步骤操作。设置您的附件视图。
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AddressTableViewCell *cell=(AddressTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.backgroundColor=[UIColor lightGrayColor];
Address *addr=[self.locationArray objectAtIndex:indexPath.row];
cell.titleLabel.text = addr.addressTitle;
cell.detailLabel.text = addr.addressDetail;
if (indexPath.row == selectedIndexPath) {
[cell.selectButton setImage:[UIImage imageNamed:@"checkboxFilled"] forState:UIControlStateNormal];
}
else {
[cell.selectButton setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
selectedIndexPath=indexPath.row;
[self.tableView reloadData];
}