私はユーザーがいくつかのフィールドを選択することができるフォームの1つを持っています。選択されたアイテムのために私は[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
を使用しました。私が使用したロジックは、私はemptyMutableArrayを取って、didSelectRowAtIndexデリゲートメソッド選択されたindexPathがそのemptyMutableArrayに存在する場合、そのアイテムが既に選択されている場合、そのemptyMutableArrayからindexPathを削除します。ただし、indexPathが存在しない場合は、そのemptyMutableArrayにindexPathを追加します。その後、同じtableViewを再ロードし、その時点でcellForRowAtIndexPathメソッドでセルを設定するためのif文をもう一度作成します。accessoryTypeここで、indexPathがemptyMutableArrayに存在するかどうかをチェックします。そうでなければ、セルのAccessoryTypeをUITableViewCellAccessoryCheckmark私はそれをUITableViewCellAccessoryNoneに設定します。 その後、問題が起こるのは、ユーザーがそのようなフォームを編集しようとするときに、すでに選択されたアイテムとその問題を表示したい場合です。 。フォームの編集時に事前チェックされたUITableViewCellを表示する方法。
これは、チェックマークを
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.font=[UIFont fontWithName:@"verdana" size:13];
cell.backgroundColor=[UIColor clearColor];
else if (tableView==roleTableView) {
cell.textLabel.text = [roleAry objectAtIndex:indexPath.row];
if([emptyMutableArray containsObject:indexPath]){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
} else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
}
cell.textLabel.textColor = [UIColor darkGrayColor];
return cell;
}
を有し、これは、ユーザが選択または選択解除すべき項目を決定そこからのtableViewのdidSelectRowAtIndexPath方法であるべきセルを決定cellForRowAtIndexPathデリゲートメソッドコードです。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
else if (tableView==roleTableView){
NSLog(@"IndexPath Obj:-%@",indexPath);
if([emptyMutableArray containsObject:indexPath]){
[emptyMutableArray removeObject:indexPath];
[roleMutableAry removeObject:[roleIdAry objectAtIndex:[roleAry indexOfObject:[NSString stringWithFormat:@"%@",[roleAry objectAtIndex:indexPath.row]]]]];
}
else {
[emptyMutableArray addObject:indexPath];
[roleMutableAry addObject:[roleIdAry objectAtIndex:[roleAry indexOfObject:[NSString stringWithFormat:@"%@",[roleAry objectAtIndex:indexPath.row]]]]];
}
NSLog(@"roleMutableAry:%@",roleMutableAry);
if ([roleMutableAry count]==0) {
//[roleBtn setTitle:@"Select role" forState:UIControlStateNormal];
}
[roleTableView reloadData];
[self loadInvitees];
[peoplesOfDiffRoleTableView reloadData];
}
}
私は私が正確な問題を表現することが典型的だった知っている、しかし、あなたは、コードを理解すれば、既に選択(チェック)のアイテム二時間を示す中に問題が発生して、どこで説明します。
あなたが実際に望むものを明確に説明する必要がありますか?どのような形ですか?私は2回読んだが、私はあなたの問題を視覚化することができない。私はあなたが "roleAry"または "roleIdAry"から "emptyMutableAry"にセルに対応するオブジェクトを追加すべきだと思います。その後、あなたの "emptyMutableAry"内のセルのタイトル値を簡単に比較することができます。 –