gpt4 book ai didi

ios - 扩展的 UITableviewCell 高度不可管理

转载 作者:行者123 更新时间:2023-11-29 12:25:12 27 4
gpt4 key购买 nike

我正在使用 this在我的应用程序中,我为 UITableview 创建了两个标识符,一个是“正常单元格”,另一个是“扩展单元格”,当有人点击“正常单元格”时它会显示。我的问题是我无法分别管理两个单元格的高度,例如我希望正常单元格高度为 120,扩展单元格为 60。但是如果我更改 heightForRowAtIndexPath 中的高度,则两个单元格显示相同的高度。这是我的代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FSParallaxTableViewCell *cell = nil;
static NSString *cellIdentifier = nil;
if ([indexPath isEqual:self.expandedIndexPath]) {
cellIdentifier = @"ExpandedCell";
}
else {
cellIdentifier = @"NormalCell";
}
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[FSParallaxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
if ([[cell reuseIdentifier] isEqualToString:@"ExpandedCell"]) {
cell.contentView.backgroundColor = [UIColor grayColor];
}
if ([[cell reuseIdentifier] isEqualToString:@"NormalCell"]) {
[cell.cellImageView sd_setImageWithURL:[NSURL URLWithString:[[rssOutputData objectAtIndex:indexPath.row]xmllink]]
placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
cell.clipsToBounds = YES;
}
return cell;
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// disable touch on expanded cell
UITableViewCell *cell = [self.theTableView cellForRowAtIndexPath:indexPath];
if ([[cell reuseIdentifier] isEqualToString:@"ExpandedCell"]) {
return;
}
// deselect row
[tableView deselectRowAtIndexPath:indexPath
animated:NO];
// get the actual index path
indexPath = [self actualIndexPathForTappedIndexPath:indexPath];
// save the expanded cell to delete it later
NSIndexPath *theExpandedIndexPath = self.expandedIndexPath;
// same row tapped twice - get rid of the expanded cell
if ([indexPath isEqual:self.expandingIndexPath]) {
self.expandingIndexPath = nil;
self.expandedIndexPath = nil;
}
// add the expanded cell
else {
self.expandingIndexPath = indexPath;
self.expandedIndexPath = [NSIndexPath indexPathForRow:[indexPath row] + 1
inSection:[indexPath section]];
}
[tableView beginUpdates];
if (theExpandedIndexPath) {
[theTableView deleteRowsAtIndexPaths:@[theExpandedIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
if (self.expandedIndexPath) {
[theTableView insertRowsAtIndexPaths:@[self.expandedIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
[tableView endUpdates];
// scroll to the expanded cell
[self.theTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}

谁能帮我解决这个问题,我想分别为两个单元格设置高度。

最佳答案

在 heightForAtIndexpath 方法中添加以下代码

 if ([indexPath isEqual:self.expandedIndexPath]) {
return 60.0;
}
else
return 120.0f;

关于ios - 扩展的 UITableviewCell 高度不可管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29342501/

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