Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox crash when update tableView
    text
    copied!<p>I had search on SO but cannot find the solution.</p> <p>My problem is checkbox is crash when update the tableView. but, everything work fine if I add the checkbox code after I update my tableView. Here my code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView2 cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView2 dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } //set up cell CGFloat nRed= 0/255.0; CGFloat nGreen=73.0/255.0; CGFloat nBlue=144.0/255.0; UIColor *myColor=[[UIColor alloc]initWithRed:nRed green:nGreen blue:nBlue alpha:1]; cell.textLabel.text = [[AryStoreknowItem objectAtIndex:indexPath.row] objectForKey:@"title"]; cell.textLabel.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:15]; cell.textLabel.textColor=myColor; cell.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.2 alpha: 1.0]; //set icon image for cell cell.imageView.image = [UIImage imageNamed: [[AryStoreknowItem objectAtIndex:indexPath.row] objectForKey:@"icon"]]; //add checkbox on cell tableView NSMutableDictionary *item = [AryStoreknowItem objectAtIndex:indexPath.row]; [item setObject:cell forKey:@"cell"]; //HERE GOT CRASH!!!!!!!!!!!!!!!!!!!!!!!!!!! BOOL checked = [[item objectForKey:@"checked"] boolValue]; UIImage *image = (checked) ? [UIImage imageNamed:@"checked.png"] : [UIImage imageNamed:@"unchecked.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height); button.frame = frame; // match the button's size with the image size [button setBackgroundImage:image forState:UIControlStateNormal]; // set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; button.backgroundColor = [UIColor clearColor]; cell.accessoryView = button; return cell; } - (void)checkButtonTapped:(id)sender event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self-&gt;tableView]; NSIndexPath *indexPath = [self-&gt;tableView indexPathForRowAtPoint: currentTouchPosition]; if (indexPath != nil) { [self tableView: self-&gt;tableView accessoryButtonTappedForRowWithIndexPath: indexPath]; } } - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *item = [selectedCheckArray objectAtIndex:indexPath.row]; BOOL checked = [[item objectForKey:@"checked"] boolValue]; [item setObject:[NSNumber numberWithBool:!checked] forKey:@"checked"]; UITableViewCell *cell = [item objectForKey:@"cell"]; UIButton *button = (UIButton *)cell.accessoryView; UIImage *newImage = (checked) ? [UIImage imageNamed:@"checked.png"] : [UIImage imageNamed:@"checked.png"]; [button setBackgroundImage:newImage forState:UIControlStateNormal]; [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; } </code></pre> <p>can anyone give me any ideas how to solve this?thanx for your time for reviewing my question</p>
 

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