1

インデックス 0 または 1 またはそれ以外を選択すると、同時に上記のインデックスに従ってインデックスも選択されます。解決策が必要です。多くの行があり、セル 1 を選択すると、同時に別のセルが自動的に選択されます。

4

1 に答える 1

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

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 に答える