.m 中 开始走起
NSIndexPath *selectIndex;//标记cell用
- (void)viewDidLoad{
selectIndex = nil;
}
//cell高度改变
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//选中之后的cell的高度
if (indexPath.row == selectIndex.row && selectIndex != nil){
return 200;
}
else
return 100;
}
//加载cell里
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//判断cell是否处于选中状态,并且用不同的identifier标记重用;
//选中的cell改变高度,同时在cell的下方添加需要的button;
if (indexPath.row == selectIndex.row && selectIndex != nil) {//选中状态
static NSString *identifier = @"cell1";
***TableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell1) {// 这里就可以添加下菜单里的东西了
cell1 = [[***TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIView *blackView = [[UIView alloc]initWithFrame:CGR(0, 100, ScreenWidth, 100)];
blackView.backgroundColor = [UIColor redColor];
[cell1.contentView addSubview:blackView];
}
cell1.selectionStyle = UITableViewCellSelectionStyleNone;
return cell1;
}
else{// 非选中状态
static NSString *identifier = @"cell";
***TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[***TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.resumeModel = resumeArry[indexPath.row];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
return nil;
}
//点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (!selectIndex) {
selectIndex = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else{
BOOL selectTheSameRow = indexPath.row == selectIndex.row?YES:NO;
//两次点击不同的cell
if (!selectTheSameRow) {
//收起上次点击展开的cell
NSIndexPath *tempIndexPath = [selectIndex copy];
selectIndex = nil;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:tempIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
//展开新选的cell
selectIndex = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else{
//相同cell 收起cell
selectIndex = nil;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
}
这样就可以实现效果了 里面东西自己弄
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了