Function: Click cell to display the details of the cell, and click Close cell details again. # Import <UIKit/UIKit. h> @ interface MyCell: UITableViewCell {UILabel * lab_info; UILabel * lab_detailInfo; CGFloat normalHeight;} @ property (retain, nonatomic) UILabel * lab_info, * comment; @ property CGFloat norheight mal; -(CGFloat) getMyCellHeight;-(void) resetCellHeight; @ end # import "MyCell. h "@ interface MyCell () {}@ end @ implementation MyCell @ synthesize lab_info, lab_detailInfo; @ synthesize normalHeight; -(Id) initWithStyle :( UITableViewCellStyle) style reuseIdentifier :( NSString *) reuseIdentifier {self = [super initWithStyle: style reuseIdentifier: reuseIdentifier]; if (self) {lab_info = [[UILabel alloc] init]; [self. contentView addSubview: lab_info]; // self. normalHeight = self. frame. size. height; // lab_detailInfo = [[UILabel alloc] init]; lab_detailInfo.lineBreakMode = NSLineBreakByCharWrapping; lab_detailInf O. numberOfLines = 5; [self. contentView addSubview: lab_detailInfo]; // self. layer. shadowColor = [UIColor blackColor]. CGColor; self. layer. shadowOffset = CGSizeMake (0, 2); self. layer. shadowOpacity = 0.3; self. layer. shadowRadius = 2; //} return self;}-(void) setSelected :( BOOL) selected animated :( BOOL) animated {[super setSelected: selected animated: animated];} -(CGFloat) getDetailLabViewHeight {[self. lab_detailInf O sizeToFit]; return self. lab_detailInfo.frame.size.height;}-(CGFloat) getMyCellHeight {return normalHeight + [self getDetailLabViewHeight];}-(void) resetCellHeight {[self layoutIfNeeded]; CGRect cellFrame = self. frame; cellFrame. size. height = normalHeight + [self getDetailLabViewHeight]; [self setFrame: cellFrame];}-(void) layoutSubviews {[super layoutSubviews]; // set the height of the title lab CGRect lab_info_Frame = CGRectI Nset (self. frame, 0, 0); Height = bytes = 0; lab_info_Frame.size.height = normalHeight; [lab_info setFrame: lab_info_Frame]; // you can specify the height of CGRect lab_detailInfo_Frame = CGRectInset (self. frame, 0, 0); lab_detailInfo_Frame.origin.x = 0; Limit = normalHeight; lab_detailInfo_Frame.size.height = [self getDetailLabViewHeight]; [lab_detailInfo setFrame: lab_detailI Nfo_Frame]; // [self setNeedsDisplay];}-(void) drawRect :( CGRect) rect {[super drawRect: rect]; self. contentView. backgroundColor = [UIColor grayColor]; lab_info.backgroundColor = [UIColor clearColor]; lab_detailInfo.backgroundColor = [UIColor clearColor];} @ end # import <UIKit/UIKit. h> # import "MyCell. h "@ interface RootViewController: UITableViewController {NSMutableArray * isItemSelected;} @ end # import" Roo TViewController. h "@ implementation RootViewController # pragma mark-# pragma mark View lifecycle-(void) viewDidLoad {[super viewDidLoad]; isItemSelected = [[NSMutableArray alloc] Priority: 5]; for (int I = 0; I <5; I ++) {[isItemSelected insertObject: [NSNumber numberWithBool: NO] atIndex: I];} # pragma mark-# pragma mark Table view data source // Customize the number of sessions in the table view. -(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 1;} // Customize the number of rows in the table view. -(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return 5;} // Customize the appearance of table view cells. -(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * CellIdentifier = @ "Cell"; MyCell * cell = [tableView failed: CellIdentifier]; if (cell = nil) {cell = (MyCell *) [[MyCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: CellIdentifier]; cell. selectionStyle = UITableViewCellSelectionStyleNone;} cell. lab_info.text = [NSString stringWithFormat: @ "title-% d", indexPath. row]; cell. lab_detailInfo.text = [NSString st RingWithFormat: @ "subtitle-% d", indexPath. row]; if ([[isItemSelected objectAtIndex: indexPath. row] boolValue] = YES) {cell. lab_detailInfo.hidden = NO;} else {cell. lab_detailInfo.hidden = YES;} www.2cto.com return cell;} # pragma mark-# pragma mark Table view delegate-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {MyCell * cell = (MyCell *) [self tableView: table View cellForRowAtIndexPath: indexPath]; if ([[isItemSelected objectAtIndex: indexPath. row] boolValue] = YES) {return [cell getMyCellHeight];} else {return cell. normalHeight;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {BOOL B = [[isItemSelected objectAtIndex: indexPath. row] boolValue]; [isItemSelected replaceObjectAtIndex: indexPath. row withObject: [N SNumber numberWithBool :! B]; // [tableView reloadData]; // [tableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationNone];} the effect is as follows: