菜鸟教程小白 发表于 2022-12-11 19:00:23

ios - 3D Peek and Pop 内存泄漏


                                            <p><p>在实现 peek and pop 之后,我看到了一个问题,即注册 View 以进行预览的 Controller 在 View 被释放后没有释放 View 。<br/>
我创建了一个带有 tableView 的简单项目,并且 viewController 将每个单元格注册为预览如下:</p>

<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PeekCell *cell = ;
    ;

    return cell;
}
</code></pre>

<p>问题是如果我上下滚动,因为单元格将被释放并创建新单元格。 viewController 将注册新的单元格以进行预览,并且以这种方式内存正在增长。<br/>
<strong>问:</strong>我做错了什么?我什么时候应该调用 <code>unregisterForPreviewingWithContext</code> ?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>不要在<code>cellForRowAtIndexPath:</code>中注册<code>previewing</code>,试试:<br/></p>

<pre><code>- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    self.previewingContext = ;
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
    ;
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 3D Peek and Pop 内存泄漏,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42274523/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42274523/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 3D Peek and Pop 内存泄漏