gpt4 book ai didi

ios - 在表格滚动的自定义表格单元格中添加 subview subview 消失该做什么 subview 返回单元格

转载 作者:行者123 更新时间:2023-11-29 02:47:35 29 4
gpt4 key购买 nike

我在自定义表格单元格中长按时添加 subview ,但是当我滚动表格时, subview 消失。 p>

我应该怎么做,以便当我向后滚动时,该 subview 仍然显示/出现在该单元格上,或者换句话说,我说单元格保持选中状态

- (IBAction)click4:(id)sender
{
//
self.lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[self.lpgr setMinimumPressDuration:1];
[self.contentView addGestureRecognizer:self.lpgr];
}
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender
{
if ([sender isEqual:self.lpgr]) {
if (sender.state == UIGestureRecognizerStateBegan)
{
self.actionButtonView = [[PerformAction alloc]initWithNibName:@"PerformAction" bundle:Nil];
[self.thirdImageView addSubview:self.actionButtonView.view];
}
}
}

最佳答案

一切都按预期进行。我想你 cellForRowAtIndexPath 是这样工作的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self cellIdentifierForIndexPath:indexPath] forIndexPath:indexPath];
id item = [self itemAtIndexPath:indexPath];
// some configuration here.
return cell;
}

因此,当您到达 dequeueReusableCellWithIdentifier 时,您就拥有了在 nib(或 Storyboard)中设计的单元格。

如果您想实现您想要做的事情,您可以添加 View 并根据单元格状态将其隐藏。长按更新此状态。

关于ios - 在表格滚动的自定义表格单元格中添加 subview subview 消失该做什么 subview 返回单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24910578/

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