gpt4 book ai didi

ios - UITableView 单元格重复

转载 作者:行者123 更新时间:2023-11-28 07:05:21 25 4
gpt4 key购买 nike

我正在开发我的第一个 Swift 应用程序,并且永远陷入了一个错误。向核心数据添加新条目时,第一次一切正常。但是,对于其他项目,先前添加的项目会在表中重复。

数据不重复,只有单元格。重新加载应用程序时,单元格会正确显示。

这是填充单元格的代码:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
if let fetchedSections: AnyObject = fetchedResultController.sections as AnyObject? {
return fetchedSections.count
} else {
return 0
}
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let fetchedSections: AnyObject = fetchedResultController.sections as AnyObject? {
return fetchedSections[section].numberOfObjects
} else {
return 0
}
}

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {

let lookup = sortedArray[indexPath.row] as! NSManagedObjectID
let spot = spotsDict[lookup] as! Spots
let cell = tableView.dequeueReusableCellWithIdentifier("SpotCell", forIndexPath:indexPath) as! SpotCell

println(sortedArray)
println(spot)

cell.spotLabel.text = spot.title

cell.spotPhoto.image = self.imagesDict[lookup]

cell.distanceLabel.text = self.distanceStringDict[lookup] as NSString! as String

cell.spotPhoto.layer.cornerRadius = 4
cell.spotPhoto.clipsToBounds = true

return cell
}

最佳答案

请替换您的代码

让 lookup = sortedArray[indexPath.row] 为! NSManagedObjectID

在 cellForRowAtIndexPath 方法中使用以下代码。

让 lookup = sortedArray[indexPath.section] 为! NSManagedObjectID

关于ios - UITableView 单元格重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802298/

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