我在自定义表格单元格中长按时添加 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/