现在为什么重复的单元格会出现在 UITableView
中?
如您在此 GIF 中所见,我按下一个单元格按钮以产生一些淡入淡出效果,但其他单元格也会受到影响!
https://media.giphy.com/media/xT0BKL5KnCgEjaXm9i/giphy.gif
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return numberOfCells
}
并且单元格的计数始终为 10
numberOfCells = 10
我总是制作表格 View 并且我确定设置,这是苹果方面的错误吗?
编辑:
如何创建单元格:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("brandCell", forIndexPath:indexPath) as! CustomCell1INF
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.frame = self.view.frame
return cell
}
最佳答案
发生这种情况是因为 UITableViewCell
被重用了。
您在按下按钮时更改了单元格,您需要在数据源模型中跟踪它。
在 cellForRowAtIndexPath
中,您必须添加一个条件来检查该按钮是否被按下,然后相应地显示适当的 View 。
关于ios - 为什么 UITableView 中会出现重复的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35443770/