UITableViewCell的prepareForReuse方法

cell被重用怎樣提早知道? 重寫cell的prepareForReuse官方頭文件裏有說明.當前已經被分配的cell假設被重用了(通常是滾動出屏幕外了),會調用cell的prepareForReuse通知cell.注意這裏重寫方法的時候,注意必定要調用父類方法[super prepareForReuse] .這個在使用cell做爲網絡訪問的代理容器時尤爲要注意,需要在這裏通知取消掉前一次網絡請求.不要再給這個cell發數據了.網絡

// if the cell is reusable (has a reuse identifier), this is called just before the cell is returned from the table view method dequeueReusableCellWithIdentifier:.  If you override, you MUST call super.

- (void)prepareForReuse
{
    [super prepareForReuse];
}
ide


自定義UITableViewCell的方法有很是多 發現一些人都會遇到自定義的cell裏面圖片錯亂的問題 這個問題每每是因爲沒有實現prepareForReuse這種方法致使的.post

UITableViewCell在向下滾動時複用, 得用的cell就是滑出去的那些, 而滑出去的cell裏顯示的信息就在這裏出現了 解決辦法就是在UITableViewCell的子類裏實現perpareForReuse方法, 把內容清空掉this

相關文章
相關標籤/搜索