我有一個應用程序,它具有嵌入ViewController中的tableview,每當我導航到另一個ViewController並導航回表格視圖時,單元格在我滾動時重複。有沒有人有任何建議如何防止這種情況?爲實現代碼如下目前的代碼是:自定義單元格重複
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return marathonRaces.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let singleCell: marathonTableViewCell = tableView.dequeueReusableCellWithIdentifier("marathonCell") as! marathonTableViewCell
singleCell.marathonName.text = marathonRaces[indexPath.row]
singleCell.entry.text = "\(entryNumber[indexPath.row])"
singleCell.entries.text = "\(entires[indexPath.row])"
singleCell.length.text = "\(length[indexPath.row])"
return singleCell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexPath = self.marathonsTableView.indexPathForSelectedRow!
let currentCell = marathonsTableView.cellForRowAtIndexPath(indexPath) as! marathonTableViewCell
let marathonEvents = currentCell.marathonName.text
self.performSegueWithIdentifier("marathonDetail", sender: self)
}
我使用的快捷,xcode7,並解析爲我的後端
內viewDidAppear唯一相關的代碼如下:
var query = PFQuery(className: 「Marathons")
query.orderByAscending("end")
query.findObjectsInBackgroundWithBlock { (marathons, error:NSError?) -> Void in
if(error == nil){
//success
for marathon in marathons! {
self.marathonRaces
.append(marathon[「marathonName"] as! String)
self.entry.append(marathon[「entryNumber"] as! Int)
self.entries.append(marathon[「entries"] as! Int)
self.length.append(marathon[「length"] as! Int)
}
self.marathonsTableView.reloadData()
}else {
print(error)
}
}
「重複」是什麼意思在「表格視圖單元格重複當我滾動」? – zaph
'marathonRaces'數組有沒有重複元素? – Deva
如果你的數組有3個項目,你將使用3個單元格,每個單元格有4個標籤!和3個標籤在所有單元格上都有相同的文字!這就是你所說的重複? –