2016-04-05 18 views
-1

この質問は以前に尋ねられたことは知っていますが、それらの間に混乱があります。セル上に複数のチェックマークが必要なので、そのセルのチェックマークをもう一度クリックすると、その選択されたセルのチェックマークをなしに設定する必要があります。私はこれを試したが、選択されたセルを再びクリックすると、選択されたセルはすべて選択されない。私はこれを試した。テーブルビューのセルでチェックボックスを取得する

- (UITableViewCell)tableView:(UITableView)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myTableViewCell" forIndexPath:indexPath]; 
cell.accessoryType = UITableViewCellAccessoryNone; 

    return cell; 
} 

とdidSelectRowAtIndexPath

- (void)tableView:(UITableView)tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath 
{ 
    myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myTableViewCell" forIndexPath:indexPath]; 
    if (cell.accessoryType == UITableViewCellAccessoryNone) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 
    else 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    } 

とdidDeselectRowAtIndexPath

-(void)tableView:(UITableView)tableView didDeselectRowAtIndexPath:(NSIndexPath)indexPath 
{ 
    myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myTableViewCell" forIndexPath:indexPath]; 
    if (cell.accessoryType == UITableViewCellAccessoryNone) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 
    else 
    { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
} 

中で助けてください。

+1

ただ、すべての権利didDeselectをtuseする必要はありません 'cellForRowAtIndexPath' –

+1

を試してみてください選択されたインデックスを配列に格納する必要があります。indexPath.rowでチェックする必要があります。cellforrowIndexPathで同じかどうかを確認してください。 –

+1

を使用して... /コメントメソッド' didDeselectRowAtIndexPath'を削除して..あなたはdidSelectRowAtIndexPathとdidDeselectRowAtIndexPathメソッド内で 'dequeueReusableCellWithIdentifier'を使用している理由 –

答えて

0

セルが選択されているかどうかにかかわらず、セルの状態を維持するだけで済みます。 cellForRowAtIndexPathでこれを試してください。

if ([tableView.indexPathsForSelectedRows containsObject:indexPath]) { 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 
else 
{ 
    cell.accessoryType = UITableViewCellAccessoryNone; 
} 
+0

それは動作していません.. –

関連する問題