Как получить все строки одной группы в TableView - PullRequest
2 голосов
/ 07 сентября 2010

Пожалуйста, помогите мне получить все строки одной группы в tableView. Я использую приведенный ниже код для показа радио / проверки в группах просмотра таблиц и хочу, чтобы для каждой группы был выбран только один.

так что для этого у меня есть 2 изображения 1: снимите флажок 2: проверено поэтому, когда пользователь щелкает / выбирает строку группы, я изменяю ее ячейку. Изображение на «проверено» и работает, но не знаю, как сделать изображения всех других ячеек этой же группы «непроверенными»

не знаю, как перебрать (получить) все строки / ячейки текущей группы

- (void)tableView:(UITableView *)tableView

didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSArray *listData =[self.tableContents objectForKey:

                    [self.sortedKeys objectAtIndex:[indexPath section]]];

NSUInteger row = [indexPath row];

NSString *rowValue = [listData objectAtIndex:row];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

cell.image = [UIImage imageNamed:@"checkbox-checked.png"];

NSString *message = [[NSString alloc] initWithFormat:rowValue];

UIAlertView *alert = [[UIAlertView alloc]

                      initWithTitle:@"You selected"

                      message:message delegate:nil

                      cancelButtonTitle:@"OK"

                      otherButtonTitles:nil];

[alert show];

[alert release];

[message release];

[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

1 Ответ

1 голос
/ 07 сентября 2010

Вот возможный обходной путь:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   // Store the section in your class
   NSUInteger section = indexPath.section;
   self.section = section; // remember to declare instance variable, property, synthesize
   self.row = row; // remember to declare instance variable, property, synthesize
   [tableView reloadData];
}

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   if (indexPath.section == self.section) {
      if (indexPath.row != self.row) {
         // then do UNCHECK here
      }
   }
}

Если вы знаете, сколько строк в вашем текущем разделе, вам не нужно вызывать reloadData, просто вызовите [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:YOUR_ROW inSection:YOUR_SECTION];

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...