テーブルビューで複数の選択を有効にする必要があります。また、選択したもの(配列などに保存するもの)を追跡する必要があります。これまでの私のアプローチ。 テーブルから複数のレコードを選択する
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[arrayobject objectAtIndex:indexPath.row];
bool xx = [[allmyselectedobjects objectAtIndex:indexPath.row] containsIndex:1];
if (xx) {
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
return cell;
}
とdidSelectRowAtIndexPath方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.cuisineTableView cellForRowAtIndexPath:indexPath];
if ([cell accessoryType] == UITableViewCellAccessoryNone) {
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[self.allmyselectedobjects insertObject:1 atIndex:indexPath.row];
}
else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
[self.allmyselectedobjects insertObject:0 atIndex:indexPath.row];
}
}
私は複数のレコードをクリックすることもできますが、私はスクロールダウンしたときに、私も(私が選択していない)のチェックマークでチェックさ他のセルを参照してください。私はこれを数日間試していますが、誰かがこのコードを修正するのを助けることができますか?
これは解決策になるかもしれません。 – Illep
上記のようにNSIndexSetを使用して、選択したセルの行インデックスを格納します。 –
をNSIndexSetの意味で使うと、allmyselectedobjectsの型をNSMutableArrayではなくNSIndexSetに変更することを意味しましたか? – Illep