我表中的单行选择n反映了它

时间:2012-06-13 09:24:50

标签: ios uitableview xcode4 uistoryboard

我想在我的表视图中做一个选择这里是我的代码任何帮助将不胜感激

- (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);


 }

1 个答案:

答案 0 :(得分: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);

}