Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove a custom icon to the UITableViewCellAccessoryCheckmark when another table row is selected
    primarykey
    data
    text
    <p>I'm using the following code to add a custom icon to the UITableViewCellAccessoryCheckmark. The problem is that the cell checkmark doesn't deselect when another row is touched/selected</p> <p>here's my code:</p> <pre><code> - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int index = indexPath.row; id obj = [listOfItems objectAtIndex:index]; //This toggles the checkmark UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; if (cell.accessoryType == UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessoryCheckmark; UIImage *image = [UIImage imageNamed:@"icon-tick.png"]; UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom]; [downloadButton setImage:image forState:UIControlStateNormal]; [downloadButton setFrame:CGRectMake(0, 0, 19, 19)]; [downloadButton setBackgroundColor:[UIColor clearColor]]; [self.tableView cellForRowAtIndexPath:indexPath].accessoryView = downloadButton; //This sets the array } else { cell.accessoryType = UITableViewCellAccessoryNone; UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom]; [downloadButton setTitle:@"" forState:UIControlStateNormal]; [downloadButton setFrame:CGRectMake(0, 0, 0, 0)]; [self.tableView cellForRowAtIndexPath:indexPath].accessoryView = downloadButton; } NSMutableData *data = [NSMutableData data]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; // Customize archiver here [archiver encodeObject:obj forKey:@"keyForYourArrayOfNSIndexPathObjects"]; [archiver finishEncoding]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"keyForYourArrayOfNSIndexPathObjects"]; NSKeyedUnarchiver *unarchiver; unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: [[NSUserDefaults standardUserDefaults] objectForKey:@"keyForYourArrayOfNSIndexPathObjects"]]; // Customize unarchiver here countryItemSelected = [unarchiver decodeObjectForKey:@"keyForYourArrayOfNSIndexPathObjects"]; [unarchiver finishDecoding]; NSLog(@"list of items %@", countryItemSelected); // Navigation logic may go here. Create and push another view controller. CitiesViewController *detailViewController = [[CitiesViewController alloc] init]; // ... // Pass the selected object to the new view controller. [self.navigationController pushViewController:detailViewController animated:YES]; } </code></pre> <p>thanks for any help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload