gpt4 book ai didi

uitableviewcell 被销毁时的 iOS 回调

转载 作者:行者123 更新时间:2023-12-01 17:15:50 26 4
gpt4 key购买 nike

当用户在 uitableview 中上下滚动时,单元格会被销毁和创建。

有没有办法检测细胞何时将要被破坏或已经被破坏?

最佳答案

假设您所说的“被销毁”实际上是指一个单元格被重用,只需在您的 UITableViewCell 派生类中实现 prepareForReuse 即可。

准备复用

准备一个可重用的单元格以供 TableView 的委托(delegate)重用。

- (void)prepareForReuse

讨论

If a UITableViewCell object is reusable—that is, it has a reuse identifier—this method is invoked just before the object is returned from the UITableView method dequeueReusableCellWithIdentifier:. For performance reasons, you should only reset attributes of the cell that are not related to content, for example, alpha, editing, and selection state. The table view's delegate in tableView:cellForRowAtIndexPath: should always reset all content when reusing a cell. If the cell object does not have an associated reuse identifier, this method is not called. If you override this method, you must be sure to invoke the superclass implementation.

可用性适用于 iOS 2.0 及更高版本。也可以看看– initWithFrame:重用标识符: @property 重用标识符声明于UITableViewCell.h

关于uitableviewcell 被销毁时的 iOS 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10785055/

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