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

标签 ios objective-c uitableview uiview

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

相关文章:

ios - URLSession实例方法 `downloadTask`错误

iOS 9 读取文件权限

iphone - NSString 中子字符串之后的子字符串

swift - 如何防止表格单元格在 Swift 中继承

iphone - 如何使用 xcode 编译器警告来确定最小 IOS 部署目标

ios - SVC 网络服务——objective-c

ios - 以编程方式创建了一个UIButton,但没有点击效果(仅文本效果)

ios - 在 iOS 中的 TabBar Controller 上滑动 viewController

objective-c - 触发设置编辑: animated: without using an edit button

objective-c - 自定义 UITableViewCell 不占据单元格的完整边界?