views:

33

answers:

1

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

}
+1  A: 

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

vodkhang
count of rows are not fix
Rajesh Rolen- DotNet Developer
Does it will reload the desired rows by calling [tableView cellForRowAtIndexPath:indexToReload]?
Toro
@Toro: what are you talking about, there is no such method? @Rajesh: so, you can use the first approach
vodkhang