关于IOS UITableView的动态高度问题
来源:互联网 发布:淘宝销量少的可以买吗 编辑:程序博客网 时间:2024/05/18 16:17
IOS的UITableView生命周期是先加载heightForRowAtIndexPath,再加载cellForRowAtIndexPath。
需求要点击CELL在CELL中要显示隐藏的VIEW,所以CELL的高度需要动态计算。
所以不能在cellForRowAtIndexPath里面算高度,我用VO对象存储了CELL的高度来初始化高度,点击表格的事件中动态计算高度并且保存在VO对象中,详见下面的代码。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [tableData count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //从XIB文件中获取模板 static NSString *CustomCellIdentifier = @"CustomCellIdentifier"; UINib *nib = [UINib nibWithNibName:@"JXManagerViewCell" bundle:nil]; [tableView registerNib:nib forCellReuseIdentifier:CustomCellIdentifier]; JXManagerViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier]; //重用表格 if (cell == nil) { cell = [[JXManagerViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CustomCellIdentifier]; } JXManagerVo *mvtemp =[tableData objectAtIndex:indexPath.row]; // if(mvtemp.isFinishFlag)// {// mvtemp.leftIcon = [NSString stringWithFormat:@"%@-1",mvtemp.leftIcon];// } NSMutableString *lefticonpath = [NSMutableString stringWithString: [mvtemp leftIcon] ]; if([mvtemp isFinishFlag]) { [lefticonpath appendString:@"-1"]; } NSString *righticonpath =[mvtemp rightIcon]; //绑定数据 cell.leftIcon =[UIImage imageNamed:lefticonpath]; cell.rightIcon = [UIImage imageNamed:righticonpath]; cell.subject = [mvtemp subject]; cell.content = [mvtemp content]; cell.floatDetailContent = [mvtemp floatDetailContent]; cell.rightIconTip = [mvtemp rightIconTip]; cell.busId= [mvtemp busId]; cell.hiddenViewArray = [mvtemp.dic objectForKey:@"history"]; //设置隐藏内容可见性 if(mvtemp.isShowHiddenDetail) { cell.hiddenview.hidden=false; }else{ cell.hiddenview.hidden=true; } cell.delegate = self;//给cell设置代理 return cell;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { tableView.delegate=nil; tableView.delegate=self; JXManagerVo *mvtemp =[tableData objectAtIndex:indexPath.row]; int cellHeight =[mvtemp.cellHeight intValue]; return cellHeight;}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @"关键动作执行"; }#pragma mark - delegate-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //处理单击操作 JXManagerViewCell *tableViewCell = (JXManagerViewCell *)[tableView cellForRowAtIndexPath:indexPath]; NSInteger sections = tableView.numberOfSections; for (int section = 0; section < sections; section++) { NSInteger rows = [tableView numberOfRowsInSection:section]; for (int row = 0; row < rows; row++) { NSIndexPath *inpath = [NSIndexPath indexPathForRow:row inSection:section]; if(indexPath.row==inpath.row && indexPath.section==inpath.section) { JXManagerVo *mvtemp =[tableData objectAtIndex:inpath.row]; if(mvtemp.isShowHiddenDetail) { mvtemp.isShowHiddenDetail=false; mvtemp.cellHeight = [[NSNumber alloc] initWithInt:MAIN_CELLS_HEIGHT]; } else{ mvtemp.isShowHiddenDetail=true; mvtemp.cellHeight = [[NSNumber alloc] initWithInt:MAIN_CELLS_HEIGHT +10+ tableViewCell.hiddenview.frame.size.height ]; } } else{ JXManagerVo *mvtemp =[tableData objectAtIndex:inpath.row]; mvtemp.isShowHiddenDetail=false; mvtemp.cellHeight = [[NSNumber alloc] initWithInt:MAIN_CELLS_HEIGHT ]; } } } [tableView reloadData]; self.tableView.contentSize = CGSizeMake(self.tableView.contentSize.width, self.tableView.contentSize.height+50); }
0 0
- 关于IOS UITableView的动态高度问题
- iOS UITableView Cell的动态高度实现
- iOS UITableView动态改变tableHeaderView的高度
- 【iOS】UITableView 动态确定cell的高度
- iOS动态改变UITableView的tableViewHeader的高度
- 动态设置uitableView的高度
- iOS UITableView Cell动态高度(使用AutoLayout)
- 关于 UITableView 中 cell 自适应高度的问题
- ios 关于UITableView UITableViewCellAccessoryCheckmark 混乱的问题
- IOS UITableView-FDTemplateLayoutCell框架高度返回问题
- IOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- ios 关于UIWebView的高度问题
- UITableView的cell 动态 定义 高度
- UITableView的cell 动态 定义 高度
- iOS8 UITableView动态加载cell的高度
- 怎么样动态改变UitableView header的高度
- iOS开发总结-UITableView 自定义cell和动态计算cell的高度
- 欧几里得定理及扩展欧几里得定理
- HDU 2865 Birthday Toy(Polya+矩阵乘法+dp)
- JSP(6):网站框架的改进mv模式(2)
- iOS-响应上下左右滑动手势
- 360浏览器 根据网页META 自动切换内核
- 关于IOS UITableView的动态高度问题
- 排列 STL
- 堆和栈究竟有什么区别?
- 非阻塞I/O–Java NIO教程
- 也谈谈权限管理:理想状态下的权限管理模型
- OCM_session0_手动建库_os5.4
- zoj1041
- 链表(一)链表的新建、反转、释放
- poj1182食物链(种类并查集)