首页 > 代码库 > 点击UITableviewCell展开收缩
点击UITableviewCell展开收缩
#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
点击UITableviewCell展开收缩
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。