UITableview 单选

uitableview  单选

  (2012-09-24 13:37:16)
转载
标签: 

it

 

- (void)tableView:(UITableView *)tableView 

didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    

    int newRow = [indexPath row];

    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;

    

    if (newRow != oldRow)

    {

        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:

                                    indexPath];

        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath

                                    lastIndexPath]; 

        oldCell.accessoryType = UITableViewCellAccessoryNone;

        lastIndexPath = [indexPath copy];//一定要这么写,要不报错

    }

    

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}


注:lastindexpath 为    NSIndexPath    * lastIndexPath; 定义的一个属性

你可能感兴趣的:(UITableview 单选)