1

When i select index 0 or 1 or any else that same time it also selected index according to above index i need solution there are many rows and when i select cell 1 same time another cell selected automatically..

4

1 回答 1

0
@property (nonatomic, retain) NSIndexPath * checkedIndexPath;

in ViewDidLoad

    self.checkedIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];//Default 1st row will be checkMarked

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kSimpleCell];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kSimpleCell]autorelease];
    }
    if (self.checkedIndexPath== indexPath)
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *currentcell = [tableView cellForRowAtIndexPath:self.checkedIndexPath];
    currentcell.accessoryType = UITableViewCellAccessoryNone;
    self.checkedIndexPath = indexPath;
    UITableViewCell *currentcell = [tableView cellForRowAtIndexPath:self.checkedIndexPath];
    currentcell.accessoryType = UITableViewCellAccessoryCheckmark;
}
于 2014-07-02T05:48:39.807 回答