ios - 为什么 UITableView 中会出现重复的单元格?

标签 ios swift uitableview

现在为什么重复的单元格会出现在 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/

相关文章:

c# - 如何删除 UIButton 设置的默认约束?

ios - 如何使用UIPickerView的选定值作为通知的content.sound?

ios - UIButton颜色在iphone 8 plus和iphone X中有渐变(iOS版本独立问题)

ios - 如何在 Swift 中循环 JSON 对象?

UITableViewCellAccessoryType 更改复选标记颜色

ios - 将新单元格添加到 UITableView 时选择 UITableViewCell 文本

ios - 在 IOS 的 webview 中不断检查互联网连接

ios - NSRegularExpression 不匹配数字符号 (#)

ios - 适用于 iOS 的 Apple Watch (WatchKit) 布局样式库

ios - 如何在 iOS 的 UITableView 中显示垂直滚动条?