Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

TableView Selection Problem

chandu1219chandu1219 Posts: 12New Users *
I have a tableview and it contains two sections the first section have 4 rows and second section have 11 rows, and I have set cell accessory type to Checkmark . So my problem is When I select the the 1st row of the first section then it will automatically selects the 11th row after the selected row. i.e 1 st row in the first section shows the checkmark and 8th row in the second section automatically shows the checkmark. I have attached the screen shot for this.How to rectify this problem please help me in this.

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,689Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Show some code.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
  • smithdale87smithdale87 Posts: 4,447iPhone Dev SDK Supporter @ @ @ @ @
    My first guess is this:

    In your cellforRowAtIndexPath method, your cells are being recycled (as they should be). So you are seeing the recycled cells still have the accessory checkmark set, because you didnt explicitly unset it. You need to add logic in your cellForRow method that will set the cells to accessory type None when it does not need a checkmark.
  • chandu1219chandu1219 Posts: 12New Users *
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @Cell;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


    if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    if (indexPath.section == 0) {

    cell.textLabel.text = [symbols objectAtIndex:indexPath.row];
    }
    else
    {
    cell.textLabel.text = [numbers objectAtIndex:indexPath.row];
    }

    return cell;
    }
    #pragma mark - Table view delegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    if (cell.accessoryType == UITableViewCellAccessoryNone) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else{
    cell.accessoryType = UITableViewCellAccessoryNone;
    }

    if (indexPath.section == 0) {

    symbol = [[NSMutableString alloc] initWithString:cell.textLabel.text];
    }
    else if (indexPath.section == 1)
    {
    number = [[NSMutableString alloc] initWithString:cell.textLabel.text];
    }
    }
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,689Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
Sign In or Register to comment.