-1
セルでアクションを実行しようとすると、8行目が繰り返し表示されます。UITableViewCellでセルの再利用を防ぐことができません:Swift
extension ExploreDetailViewController: UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return specificItemInfo.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return specificItemInfo[section].subItemArray!.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PriceCell", forIndexPath: indexPath) as! PriceTableViewCell
cell.configureCell1(specificItemInfo[indexPath.section].subItemArray![indexPath.row], specificItemInfo: specificItemInfo[(indexPath.section)])
cell.delegate = self
return cell
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCellWithIdentifier("ItemCell") as! ItemTableViewCell
cell.configureCell(specificItemInfo[section])
return cell
}
セル内では、ラベルの値を設定するボタンを使用しています。しかし、1つのセルに設定された値は、8セル以下になります。それを防ぐ方法はありますか?セル内
セルをロードするたびにラベルをリセットします。したがって、cell.configureCell1を呼び出す前にcell.yourlabel.text = ""にラベルをリセットする – Devster101
セルサブクラスで '-prepareForReuse:'をオーバーライドしても同じ結果を得ることができます –
@RichTolley - prepareForReuseはこのために使用すべきではありません。ここに公式のUITableViewのドキュメントからの引用があります。パフォーマンス上の理由から、アルファ、編集、選択状態など、コンテンツに関連しないセルの属性のみをリセットする必要があります。ここにリンクがあります - https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instm/UITableViewCell/prepareForReuse – itskoBits