如何设置indexpath.row = i

时间:2014-03-03 04:07:49

标签: uitableview

- (void)checkSelected:(NSMutableArray *)dataUser
{
    NSNumber * number = [[NSUserDefaults standardUserDefaults]objectForKey:@"treatment"];

    for (NSInteger i = 0; i < dataUser.count; i++)
    {
        Treatment *treatment = (Treatment *)[dataUser objectAtIndex:i];
        if ([treatment.treatment_id isEqualToNumber:number])
        {
            NSIndexPath *indexpath = nil;
            //indexpath.row = i;
            DLog(@"index path:%d",indexpath.row);
            TreatementUserCell *cell = (TreatementUserCell*) [self.treatementUserTable cellForRowAtIndexPath:indexpath];
            if (cell.accessoryType == UITableViewCellAccessoryCheckmark ) {
                cell.accessoryType = UITableViewCellAccessoryNone;
                UIImageView *image= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pick.png"]];
                cell.accessoryView = image;

            }

            break;
        }
    }
}

我想设置indexPath.row = i,但indexPath是readonly。我该如何设置?

2 个答案:

答案 0 :(得分:0)

阅读NSIndexPath文档以发现方法indexPathForRow:inSection:

答案 1 :(得分:0)

NSIndexPath包含RowsSections,请尝试使用此代码为NSIndexPath分配值

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection: section];