#import "ViewController.h" #import "ZSDTestCell.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> { NSMutableArray *dataArray; //数组保存显示内容 NSIndexPath *selectIndex; //记录当前选择的索引 } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; dataArray=[NSMutableArray array]; for (int i=0; i<20; i++) { [dataArray addObject:[NSString stringWithFormat:@"%d",i]]; } selectIndex=nil; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath==selectIndex) { return 88.0; } return 44.0f; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UIImage *normalImg = [UIImage imageNamed:@"member_icon_more"]; UIImage *selectImg = [UIImage imageNamed:@"common_icon_down"]; ZSDTestCell *testCell=[tableView dequeueReusableCellWithIdentifier:@"ZSDTestCell" forIndexPath:indexPath]; testCell.firstLabel.text=dataArray[indexPath.row]; if (selectIndex==indexPath) { testCell.remindImageView.image=selectImg; testCell.secondLabel.text=[NSString stringWithFormat:@"测试第%@行UITableviewCell收缩效果",dataArray[indexPath.row]]; } else { testCell.remindImageView.image=normalImg; testCell.secondLabel.text=nil; } return testCell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(selectIndex==nil) { selectIndex=indexPath; } else { bool selectedOtherRow=![selectIndex isEqual:indexPath]; selectIndex=nil; if(selectedOtherRow) { selectIndex=indexPath; } } [tableView reloadData]; } @end
时间: 2024-10-09 21:53:13