I am confused a little bit about settings table view cell accessories.
I have fixed two sections in my table
What I want is as follow....
I have tried following code. But I found that indexpath.row & indexpath.section is readonly properties.
// Override to support row selection in the table view. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tblProfileView deselectRowAtIndexPath:indexPath animated:YES]; int i,max; UITableViewCell *x; NSIndexPath *tt; for(i=0;i<[tblProfileView numberOfRowsInSection:0];i++) { tt.row=i; tt.section=0; x=[tblProfileView cellForRowAtIndexPath:]; [x setAccessoryType:UITableViewCellAccessoryNone]; } for(i=0;i<[tblProfileView numberOfRowsInSection:1];i++) { tt.row=i; tt.section=1; x=[tblProfileView cellForRowAtIndexPath:tt]; [x setAccessoryType:UITableViewCellAccessoryNone]; } x=[tblProfileView cellForRowAtIndexPath:indexPath]; [x setAccessoryType:UITableViewCellAccessoryCheckmark]; // Navigation logic may go here -- for example, create and push another view controller. // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; // [self.navigationController pushViewController:anotherViewController animated:YES]; // [anotherViewController release]; }
I would keep track of the data that should be checked and change the cell in tableView:didSelectRowAtIndexPath: and update which data is checked in tableView:cellForRowAtIndexPath: like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // do usual stuff here including getting the cell // determine the data from the IndexPath.row if (data == self.checkedData) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // determine the selected data from the IndexPath.row if (data != self.checkedData) { self.checkedData = data; } [tableView reloadData]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With