The secondary expansion function of the [original] list. Extends the implementation on native UITableView ., Uitableview
Or directly paste the code.
Step 1:
@ Interface TodoViewController () {// declare an array to store cell information NSMutableArray * grouparr;} @ end
Step 2:
// Save the cell status to the array-(void) initDataSource {NSMutableDictionary * nameAndStateDic1 = [NSMutableDictionary dictionaryWithObjectsAndKeys: @ "TodoCell", @ "cell", @ "NO ", @ "state", nil]; NSMutableDictionary * nameAndStateDic2 = [NSMutableDictionary dictionaryWithObjectsAndKeys: @ "TodoCell", @ "cell", @ "NO", @ "state", nil] NSMutableDictionary * nameAndStateDic3 = [NSMutableDictionary example: @ "TodoCell", @ "cell", @ "NO", @ "state", nil]; NSMutableDictionary * nameAndStateDic4 = [response failed: @ "TodoCell", @ "cell", @ "NO", @ "state", nil]; grouparr = [NSMutableArray alloc] handler: nameAndStateDic1, nameAndStateDic2, nameAndStateDic3, nameAndStateDic4, nil];}
Step 3:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return grouparr.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if ([grouparr[indexPath.row][@"cell"] isEqualToString:@"TodoCell"]) { static NSString *cellID = @"cell"; TodoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[TodoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } NSData *data = dataArray[indexPath.row]; [cell bindData:data]; return cell; } else { static NSString *CellIdentifier = @"AttachedCell"; AttachedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[AttachedCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } return nil; }
Step 4:
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {// click cell to change the cell color gradient [_ tableView deselectRowAtIndexPath: indexPath animated: YES]; NSIndexPath * path = nil; if ([grouparr [indexPath. row] [@ "cell"] isw.tostring: @ "MainCell"]) {if ([grouparr [indexPath. row] [@ "cell"] isw.tostring: @ "MainCell"]) {path = [NSIndexPath indexPathForItem :( indexPath. row + 1) inSection: indexPath. section];} else if ([grouparr [indexPath. row] [@ "cell"] isw.tostring: @ "AttachedCell"]) {path = indexPath;} NSLog (@ "the current row is % ld", indexPath. row); if ([grouparr [indexPath. row] [@ "state"] boolValue]) {// close the additional cell NSMutableDictionary * dd = grouparr [indexPath. row]; NSString * name = dd [@ "name"]; NSMutableDictionary * nameAndStateDic = [NSMutableDictionary dictionaryWithObjectsAndKeys: @ "MainCell", @ "cell", name, @ "name ", @ "NO", @ "state", nil]; grouparr [(path. row-1)] = nameAndStateDic; [grouparr removeObjectAtIndex: path. row]; NSLog (@ "MainCell's grouparr: % @", grouparr); [_ tableView beginUpdates]; [_ tableView deleteRowsAtIndexPaths: @ [path] withRowAnimation: parent]; [_ tableView endUpdates];} else {// open the additional cell NSMutableDictionary * dd = grouparr [indexPath. row]; NSString * name = dd [@ "name"]; NSMutableDictionary * nameAndStateDic = [NSMutableDictionary dictionaryWithObjectsAndKeys: @ "MainCell", @ "cell", name, @ "name ", @ "YES", @ "state", nil]; grouparr [(path. row-1)] = nameAndStateDic; NSMutableDictionary * nameAndStateDic1 = [NSMutableDictionary Syntax: @ "AttachedCell", @ "cell", @ "YES", @ "state", nil]; [grouparr insertObject: nameAndStateDic1 atIndex: path. row]; NSLog (@ "AttachedCell's grouparr: % @", grouparr); [_ tableView beginUpdates]; [_ tableView insertRowsAtIndexPaths: @ [path] withRowAnimation: parent]; [_ tableView endUpdates] ;}}
Work done!