Note that there are some explanatory texts on larger screens.

plurals
  1. POTableView rows With CheckBox in iPhone
    text
    copied!<p>I'm developing an application and am stuck on one thing. I've tried to resolve my problem on my own, but couldn't figure it out. If some one knows how to solve this, please help me out.</p> <p>I created one UITableView with a checkbox in every row. When any checkbox is tapped I want only that checkbox selected, but currently only last check box is selected. I've provided my current code below, please let me know if you see anything that should be changed.</p> <p>Thanks.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [selectPlayer objectAtIndex:indexPath.row]; checkboxButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 8, 25, 25)]; checkboxButton.tag = indexPath.row; [checkboxButton setTitle:nil forState:UIControlStateNormal]; [checkboxButton addTarget:self action:@selector(checkboxButton:)forControlEvents:UIControlEventTouchUpInside]; [checkboxButton addSubview:checkImage]; cell.accessoryView = checkboxButton; return cell; } -(void)checkboxButton:(id)sender { NSIndexPath *indexPath = [selectTableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; switch (indexPath.section) { case 0: switch (indexPath.row) { case 0: [checkImage setImage:[UIImage imageNamed:@"checkbox-checked.png"]]; NSLog(@"button pressed at section %d and %d row", indexPath.section, indexPath.row); break; case 1: //[checkImage setImage:[UIImage imageNamed:@"checkbox-checked.png"]]; NSLog(@"button pressed at section %d and %d row", indexPath.section, indexPath.row); break; default: break; } break; default: break; } } </code></pre>
 

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