Here, I sorted out a more convenient method. The idea is to set an identifier for the cell, isSpread, expanded or unexpanded, set the height of the cell to 200, and set the height of the unexpanded cell to 100. By changing the identifier and refreshing the height of the cell, the effect of expanding and shrinking the cell can be achieved

– (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

// Cell expansion 20160606

ArewDataModle*modle =self.sectionDataArr3[indexPath.row];

if(modle.isSpread==NO) {

return55;

}else{

return100;

}

}

// Key code in CellForRow

– (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

cell.spreadImage.hidden=NO;

if(self.sectionDataArr3[indexPath.row].isSpread==NO)

{

}else{

cell.additionalLabel.hidden=NO;

}

UITapGestureRecognizer*tapSpreadImage = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(SpreadImageClick:)];

// Pass the current gesture

tapSpreadImage.delegate=self;

[cell.spreadImageaddGestureRecognizer:tapSpreadImage];

}

– (void)SpreadImageClick:(UITapGestureRecognizer*)tap{

// Pass the current gesture to identify the clicked cell

ArewTableViewCell* cell = (ArewTableViewCell*)tap.view.superview.superview;

NSIndexPath*indexpath = [self.brewTimeTableindexPathForCell:cell];

// Cell expansion

ArewDataModle*modle =self.sectionDataArr3[indexpath.row];

modle.isSpread= ! modle.isSpread;

cell.additionalLabel.hidden= ! self.isSpreadImage;

[self.ArewTimeTablereloadRowsAtIndexPaths:[NSArrayarrayWithObjects:indexpath,nil]withRowAnimation:UITableViewRowAnimatio nNone];

}



There is another way to add a self-defined cell under the current cell when you click a cell on the network, focusing on processing the data source array

This code is sorted out online.

@property(weak,nonatomic)IBOutletUITableView*my_tableView;

@property(nonatomic,strong)NSMutableArray*dataArray;

@property(assign)BOOLisOpen;

@end

@implementationMoveCell

– (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil

{

self=[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];

if(self) {

// Custom initialization

}

returnself;

}

– (void)viewDidLoad

{

[superviewDidLoad];

[selfsetTitle: @ “my cell”].

[selfsetLeftButtonText:@””andBackground:[UIImageimageNamed:@”btn_back”]];

NSDictionary*dic =@{@”Cell”:@”MainCell”,@”isAttached”:@(NO)};

NSArray* array =@[dic,dic,dic,dic,dic,dic];

self.dataArray= [[NSMutableArrayalloc]init];

self.dataArray= [NSMutableArrayarrayWithArray:array];

}

– (NSInteger)tableView:(UITableView*)tableView

numberOfRowsInSection:(NSInteger)section

{

// Return the number of rows in the

section.

returnself.dataArray.count;;

}

– (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView

{

// Return the number of sections.

return1;

}

// tableViewCell

-(UITableViewCell*)tableView:(UITableView*)tableView

cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

if([[self.dataArray[indexPath.row]objectForKey:@”Cell”]isEqualToString:@”MainCell”])

{

staticNSString*CellIdentifier =@”MainCell”;

DDIUICtrl_messageCell*cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

if(cell ==nil) {

cell = [[DDIUICtrl_messageCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

cell.selectionStyle=UITableViewCellSelectionStyleGray;

}

//

cell.Headerphoto.image = [UIImage imageNamed:[NSString

stringWithFormat:@”%d.jpg”,indexPath.row%4+1]];

returncell;

}elseif([[self.dataArray[indexPath.row]objectForKey:@”Cell”]isEqualToString:@”AttachedCell”]){

staticNSString*CellIdentifier =@”AttachedCell”;

DDUICtrl_menuCell*cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

if(cell ==nil) {

cell = [[DDUICtrl_menuCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

cell.selectionStyle=UITableViewCellSelectionStyleNone;

}

returncell;

}

returnnil;

}

// tableView click event

-(void)tableView:(UITableView*)tableView

didSelectRowAtIndexPath:(NSIndexPath*)indexPath{

[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];

NSIndexPath*path =nil;

if([[self.dataArray[indexPath.row]objectForKey:@”Cell”]isEqualToString:@”MainCell”]) {

path = [NSIndexPathindexPathForItem:(indexPath.row+1)inSection:indexPath.section];

}else{

path

= indexPath;

}

if([[self.dataArray[indexPath.row]objectForKey:@”isAttached”]boolValue]) {

// Close the attached cell

NSDictionary* dic =@{@”Cell”:@”MainCell”,@”isAttached”:@(NO)};

self.dataArray[(path.row-1)] = dic;

[self.dataArrayremoveObjectAtIndex:path.row];

[self.my_tableViewbeginUpdates];

[self.my_tableViewdeleteRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationMiddle];

[self.my_tableViewendUpdates];

}else{

// Open the attached cell

NSDictionary* dic =@{@”Cell”:@”MainCell”,@”isAttached”:@(YES)};

self.dataArray[(path.row-1)] = dic;

NSDictionary* addDic =@{@”Cell”:@”AttachedCell”,@”isAttached”:@(YES)};

[self.dataArrayinsertObject:addDicatIndex:path.row];

[self.my_tableViewbeginUpdates];

[self.my_tableViewinsertRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationMiddle];

[self.my_tableViewendUpdates];

}

}

@end