Expand/collapse section in UITableView in iOS

前端 未结 17 781
野的像风
野的像风 2020-11-22 08:49

Could somebody tell me the way to perform UITableView expandable/collapsible animations in sections of UITableView as below?

<

17条回答
  •  死守一世寂寞
    2020-11-22 09:37

    This action will happen in your didSelectRowAtIndexPath, when you will try to hide or show number of cell in a  section
    
    first of all declare a global variable numberOfSectionInMoreInfo in .h file and in your viewDidLoad set suppose to numberOfSectionInMoreInfo = 4.
    
    Now use following logic: 
    
    
     // More info link
            if(row == 3) {
    
                /*Logic: We are trying to hide/show the number of row into more information section */
    
                NSString *log= [NSString stringWithFormat:@"Number of section in more %i",numberOfSectionInMoreInfo];
    
                [objSpineCustomProtocol showAlertMessage:log];
    
                // Check if the number of rows are open or close in view
                if(numberOfSectionInMoreInfo > 4) {
    
                    // close the more info toggle
                    numberOfSectionInMoreInfo = 4;
    
                }else {
    
                    // Open more info toggle
                    numberOfSectionInMoreInfo = 9;
    
                }
    
                //reload this section
                [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
    

    //vKj

提交回复
热议问题