2012-06-13 3 views
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); 


} 
+0

эй получил ответ ... текущая категория является строка не массив .. – newstar7867

ответ

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

}

Смежные вопросы