2

I have used third party expandable table view named "ExpandableTableView",when i want to expand particular single section using custom button in my view.my code snippet is :

UIView *view=Gesture.view;
    isFirsTime=NO;
    //NSLog(@"%ld",(long)view.tag);
    for (int h=0; h<dicAll.count; h++)
    {
        NSString *strRegisterId=[[[dictStatndardDefectsResult valueForKey:@"defectdata:"]valueForKey:@"projectdefectid"]objectAtIndex:h];
        NSString *strBtnTag=[NSString stringWithFormat:@"%ld",(long)view.tag];
        if ([strRegisterId isEqualToString:strBtnTag])
        {
            btnIndex=h;
           // NSLog(@"%ld",(long)btnIndex);
            isTappedMarker=YES;

        }
    }
    NSMutableArray *indexPaths=[[NSMutableArray alloc]init];
    [indexPaths addObject:[NSIndexPath indexPathForRow:0 inSection:btnIndex]];

        NSLog(@"%@",arrDefectImages);

        NSLog(@"numberOfRowsInSection: %ld",(long)[self tableView:tblSupplierDefect numberOfRowsInSection:btnIndex]);
        [tblSupplierDefect beginUpdates];

        [self.tblSupplierDefect insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
        [tblSupplierDefect endUpdates];

where the btnIndex is section number which i want to expand.

Rajat
  • 10,977
  • 3
  • 38
  • 55

1 Answers1

0

I have achieved something like that by using this:

func didTapOnHeader(tapGesture: UITapGestureRecognizer) {

    let view = tapGesture.view as! ViewHeader

    // collapse if already expended.
    if view.tag == self.dataBinder.selectedSection {

        //collaps the section
        self.dataBinder.selectedSection = nil
        self.tableView.reloadSections(NSIndexSet(index:view.tag), withRowAnimation: UITableViewRowAnimation.Automatic)

    }else {

        // collapse last selected section, at a time one section should be selected.
        self.dataBinder.selectedSection = nil
        self.tableView.reloadData()

        //expand plan details
        self.dataBinder.selectedSection = view.tag
        self.tableView.reloadSections(NSIndexSet(index:view.tag), withRowAnimation: UITableViewRowAnimation.Automatic)
    }
}


func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let view = ViewHeader.instanceFromNib()
    view.tag = section
    let gesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.didTapOnHeader(_:)))
    view.addGestureRecognizer(gesture)

    //### Assignment ###
    view.planDescriptionLabel.text = plan.planDescription

    return view
}

This will close perviously selected sections and will expand only one section at ta time.

iBug
  • 2,334
  • 3
  • 32
  • 65