iOS开发笔记-cell里点击按钮展开收起-动态改变cell行高
2015-11-25 17:54
295 查看
1.cell for row
<span style="white-space:pre"><span style="background-color: rgb(255, 255, 255);"> </span></span><span style="background-color: rgb(255, 255, 255);">//配置cell</span>
//这里我用一个方法统一来计算高度
return [calcuH cellHeight:dic];
//-----------------------------------------------
-(CGFloat)cellHeight:(NSDictionary *)dic{
//45 26+
CGFloat heightt = 45+26+5;
/*评价内容*/ //在我的另一篇文章里有这个方法,地址:http://blog.csdn.net/jp940110jpjp/article/details/42262021
CGSize labContextWidth = [calculatorStringSize stringSize:[dic objectForKey:@"evaluateContext"] widthOfFatherView:WIDTH-20 textFont:[UIFont systemFontOfSize:11.0]];
if ([[dic safeNullWithKey:@"iszhankai"] isEqualToString:@"1"]) {
heightt+= labContextWidth.height;
}else{
if (labContextWidth.height>=30) {
heightt+= 30+10+14;
}else{
heightt+= labContextWidth.height;
}
}
CGFloat imgVWidth = (SCREEN_WIDTH-26-18) /4.0;
NSArray *imageArray = dic[@"evaluateIcons"];
if (imageArray.count>=1) {
heightt+= 10+imgVWidth+15+12+20;
}else{
heightt+= 10+15+12+20;
}
return heightt;
}
OK,大致这些,写的很粗糙,还有很多需要优化的地方,cell里的配置方法,根据dic里的@"iszhankai"参数进行相应的配置就行,有好的建议欢迎大家提出来
<span style="white-space:pre"><span style="background-color: rgb(255, 255, 255);"> </span></span><span style="background-color: rgb(255, 255, 255);">//配置cell</span>
<span style="white-space: pre;"> </span><span style="background-color: rgb(255, 255, 255);">[cell congigCell:cell.dic];</span>
<span style="background-color: rgb(255, 255, 255);"><span style="white-space:pre"> </span>//下拉展开按钮 cell.ZhankaiBtn.tag = indexPath.row+1000; [cell.ZhankaiBtn addTarget:self action:@selector(zhankai:) forControlEvents:UIControlEventTouchUpInside]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell;</span>
<span style="background-color: rgb(255, 255, 255);">2.按钮点击事件</span>
<span style="font-size:10px;background-color: rgb(255, 255, 255);"></span><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;">-(void)zhankai:(UIButton *)btn{</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> <span style="white-space:pre"> </span>NSMutableDictionary *dic;</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> <span style="white-space:pre"> </span>btn.selected = !btn.selected;</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> <span style="white-space:pre"> </span>dic = [NSMutableDictionary dictionaryWithDictionary:self.valueArray[btn.tag-1000]];</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;">//1 2 标识一种状态 1代表展开状态 2代表闭合状态</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> if ([[dic safeNullWithKey:@"iszhankai"] isEqualToString:@"2"]) {</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo; min-height: 21px;"> [dic setObject:@"1" forKey:@"iszhankai"];</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> }else if ([[dic safeNullWithKey:@"iszhankai"] isEqualToString:@"1"]) {</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> [dic setObject:@"2" forKey:@"iszhankai"];</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> }else{</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> [dic setObject:@"1" forKey:@"iszhankai"];</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> }</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> [self.valueArray replaceObjectAtIndex:btn.tag-1000 withObject:dic];</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo;"> <span style="white-space:pre"> </span>NSIndexPath *path = [NSIndexPath indexPathForRow:btn.tag-1000 inSection:1];</p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: Menlo; min-height: 21px;"> <span style="white-space:pre"> </span>[self.ev_tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationAutomatic];</p>2.height for row
//这里我用一个方法统一来计算高度
return [calcuH cellHeight:dic];
//-----------------------------------------------
-(CGFloat)cellHeight:(NSDictionary *)dic{
//45 26+
CGFloat heightt = 45+26+5;
/*评价内容*/ //在我的另一篇文章里有这个方法,地址:http://blog.csdn.net/jp940110jpjp/article/details/42262021
CGSize labContextWidth = [calculatorStringSize stringSize:[dic objectForKey:@"evaluateContext"] widthOfFatherView:WIDTH-20 textFont:[UIFont systemFontOfSize:11.0]];
if ([[dic safeNullWithKey:@"iszhankai"] isEqualToString:@"1"]) {
heightt+= labContextWidth.height;
}else{
if (labContextWidth.height>=30) {
heightt+= 30+10+14;
}else{
heightt+= labContextWidth.height;
}
}
CGFloat imgVWidth = (SCREEN_WIDTH-26-18) /4.0;
NSArray *imageArray = dic[@"evaluateIcons"];
if (imageArray.count>=1) {
heightt+= 10+imgVWidth+15+12+20;
}else{
heightt+= 10+15+12+20;
}
return heightt;
}
OK,大致这些,写的很粗糙,还有很多需要优化的地方,cell里的配置方法,根据dic里的@"iszhankai"参数进行相应的配置就行,有好的建议欢迎大家提出来
相关文章推荐
- iOS开发之路--微博“更多”页面
- NSString与C字符串之间的相互转换
- iOS开发之路--微博骨架搭建
- IOS开发代码分享之获取启动画面图片的string
- IOS开发之路--C语言数组和字符串
- IOS开发代码分享之用nstimer实现倒计时功能
- UITableView 实现汽车品牌(demo)
- IOS开发代码分享之设置UISearchBar的背景颜色
- IOS 9 UITableView整理
- ios开发之环境搭建-01
- UITableView 基本使用方法总结
- UITableView一些易混属性和方法
- 在开发iOS程序时对日期处理的总结
- UITableView的详细讲解
- iOS开发——keychain的使用
- iOS Graphics Technologies iOS 图形技术
- iOS开发异常错误总结
- (转)UITableViewController重要配置方法和Delegate
- NSString 用法2
- NSString 用法3