保证tableview Checkmark的选中唯一性

来源:互联网 发布:21端口被占用 编辑:程序博客网 时间:2024/06/02 15:55
@property (nonatomicstrongNSIndexPath *selectedIndexPath;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
static NSString *CellIdentifier = @"YFCELLEDITDOCACADEMIC";
    
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
if (cell == nil) {
        cell = [[
UITableViewCell allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
//config the cell
    
    cell.
textLabel.text=[academicArray[indexPath.row]objectForKey:@"Typename"];
    cell.
tag=[[academicArray[indexPath.row]objectForKey:@"Typeid"]intValue];
    
if ([self.selectedIndexPath isEqual:indexPath])
        cell.
accessoryType = UITableViewCellAccessoryCheckmark;
    
else
        cell.
accessoryType = UITableViewCellAccessoryNone;
    
return cell;
}
-(
void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
if (self.selectedIndexPath) {
        
UITableViewCell *cell = [tableView cellForRowAtIndexPath:self.selectedIndexPath];
        cell.
accessoryType = UITableViewCellAccessoryNone;
    }
    
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.
accessoryType = UITableViewCellAccessoryCheckmark;
    
self.selectedIndexPath = indexPath;
    
    [tableView 
deselectRowAtIndexPath:indexPath animated:YES];
    
}
0 0
原创粉丝点击