gpt4 book ai didi

ios - 如何在 UITableView 中实现 Expandable - Collapsable UITableViewCell - IOS

转载 作者:行者123 更新时间:2023-12-01 18:58:08 26 4
gpt4 key购买 nike

我接近了UITableview获取单元格点击ExpandView .我想要实现这样的事情。

Exapand cell View

所以,UITableView将是最好的方法或建议我任何好的实现方式,我也无法获得 subview根据screenSize调整.

最佳答案

可能有其他方法可以实现这一点,但这就是我的扩展方式UITableViewCell在飞行中。这可以给出想法,您可以实现您的解决方案。

我在数据模型中保留行高:

- (void)viewDidLoad {
[super viewDidLoad];

//Data source
datasource = [[NSMutableArray alloc] init];
NSMutableDictionary *aDicti = [[NSMutableDictionary alloc] init];
[aDicti setValue:@"a TEXT" forKey:@"text"];
[aDicti setValue:@(50) forKey:@"cellheight"]; // here
}

When selection changed, just updating related key in data source.
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates];
[[datasource objectAtIndex:indexPath.row] setObject:@(50) forKey:@"cellheight"];
[tableView endUpdates];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView beginUpdates];
[[datasource objectAtIndex:indexPath.row] setObject:@(200) forKey:@"cellheight"];
[tableView endUpdates];
}

一次 [tableView endUpdates];执行 heightForRowAtIndexPathnumberOfRowsInSection委托(delegate)方法触发并使用数据源中的值自动调整单元格高度。
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [[[datasource objectAtIndex:indexPath.row] objectForKey:@"cellheight"] intValue];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return datasource.count;
}

如果您不想在数据源中保留行高,您基本上可以应用它。
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates];
[tableView endUpdates];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView beginUpdates];
[tableView endUpdates];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView.indexPathForSelectedRow.row == indexPath.row) {
return 100;
}
return 50;
}

关于ios - 如何在 UITableView 中实现 Expandable - Collapsable UITableViewCell - IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25056565/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com