0

テーブルビューで単一選択を行いたい ここに私のコードがあります 助けていただければ幸いです ありがとう

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{ // 選択ロジックは、選択された国の横に目盛りを付けるためにここに行きます

currentCategory = [[NSMutableArray alloc] init];



[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSInteger catIndex = [countryList indexOfObject:self.currentCategory];
if (catIndex == indexPath.row) {
    return;
}
NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:catIndex inSection:0];

UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if (newCell.accessoryType == UITableViewCellAccessoryNone) {
    newCell.accessoryType = UITableViewCellAccessoryCheckmark;
    self.currentCategory = [countryList objectAtIndex:indexPath.row];
}

UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark) {
    oldCell.accessoryType = UITableViewCellAccessoryNone;
}

NSLog(@"the selected cell is %@",newCell);


 }
4

1 に答える 1

0

現在のカテゴリは文字列であり、配列ではありません。ここに正しいコードがあります

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{{

[tableView deselectRowAtIndexPath:indexPath animated:NO];

NSInteger genderIndex = [genderList indexOfObject:self.selectedGender];

if (genderIndex == indexPath.row) {
    return;
}

NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:genderIndex inSection:0];

UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if (newCell.accessoryType == UITableViewCellAccessoryNone) {
    newCell.accessoryType = UITableViewCellAccessoryCheckmark;
    self.selectedGender = [genderList objectAtIndex:indexPath.row];
}

UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark) {
    oldCell.accessoryType = UITableViewCellAccessoryNone;
}

NSLog(@"the selected cell is %@",selectedGender);

}

于 2012-06-13T18:08:02.357 に答える