开发者

How to get all rows of same group in TableView

开发者 https://www.devze.com 2023-01-14 22:22 出处:网络
Please help me to get all rows of same group in tableView. i am using below code to show radio/check in groups of tableview and want the only one per group selection.

Please help me to get all rows of same group in tableView. i am using below code to show radio/check in groups of tableview and want the only one per group selection.

so for that i have got 2 images 1:uncheck 2:checked so when user will click/select a row of group than i am changing its cell.image to "checked" and its working but don't know how to make all other cell's images of same group's to "unchecked"

dont know how to loop through (get) all rows/cells of current group

开发者_高级运维- (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];

}


Here is a possible workaround:

- (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
      }
   }
}

If you know how many rows in your current section, you don't need to call reloadData, just call [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:YOUR_ROW inSection:YOUR_SECTION];

0

精彩评论

暂无评论...
验证码 换一张
取 消