gpt4 book ai didi

ios - 使用 reloadRowsAtIndexPaths 或 reloadSections 导致 Tableview Cell 闪烁

转载 作者:行者123 更新时间:2023-11-29 01:35:18 24 4
gpt4 key购买 nike

我正在尝试使用 reloadRowsAtIndexPathsreloadSections 在该单元格内的分段开关发生更改(这反过来又更改了 tableView 单元格中的显示)时重新加载该单元格UIScrollView 在该单元格内)。使用它会导致最后一个 tableView 单元格(与重新加载的单元格无关)闪烁:单元格的背景短暂地变为黑色。最后一个 tableView 单元格与其他单元格不同,因为它包含一个 UICollectionView(见下图)。 tableView 中的所有单元格都是清晰的,backgroundView 控制背景颜色渐变。

//tableView cellForRowAtIndexPath 
case .cellToReload:
let cell = tableView.dequeueReusableCellWithIdentifier("graphs", forIndexPath: indexPath) as! WeatherTableViewCell
cell.selectionStyle = UITableViewCellSelectionStyle.None
let segmentControl = cell.viewWithTag(1) as! UISegmentedControl
segmentControl.selectedSegmentIndex = segment
segmentControl.addTarget(self, action: "segmentAction:", forControlEvents: .ValueChanged)
cell.graph.delegate = self
cell.graph.showsHorizontalScrollIndicator = false
if segment == 0 || segment == 1 {
cell.graph.contentSize.width = cell.frame.width * 2.0
} else {
cell.graph.contentSize.width = cell.frame.width
}
cell.graph.contentSize.height = cell.graph.frame.height
let ConditionsView = UIView(frame: CGRectMake(20, 0, cell.graph.contentSize.width, cell.graph.contentSize.height))
cell.backgroundColor = UIColor.clearColor()
switch (segment) {
//create new view and add as a subview to cell.graph

case .flickeringCell:
let cell = tableView.dequeueReusableCellWithIdentifier("weeklyWeatherCell", forIndexPath: indexPath) as! WeatherTableViewCell
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.forecastCollectionView.delegate = self
cell.forecastCollectionView.dataSource = self
cell.forecastCollectionView.reloadData()
cell.forecastCollectionView.tag = indexPath.row
cell.forecastCollectionView.showsHorizontalScrollIndicator = false
cell.backgroundColor = UIColor.clearColor()
cell.forecastCollectionView.backgroundView = cell.backgroundView
cell.forecastCollectionView.backgroundColor = cell.backgroundColor
return cell


func segmentAction(sender: UISegmentedControl) {
let path = NSIndexSet(index: 1)
switch sender.selectedSegmentIndex {
case 0:
segment = 0
tableView.reloadSections(path, withRowAnimation: .Fade)
case 1:
segment = 1
tableView.reloadSections(path, withRowAnimation: .Fade)
case 2:
segment = 2
tableView.reloadSections(path, withRowAnimation: .Fade)
default:
break
}

}

//Table background
func createGradientForTable {
let gradientLayer = CAGradientLayer()
...
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 0, y: 1)
let backgroundView = UIView(frame: sender.tableView.frame)
backgroundView.layer.insertSublayer(gradientLayer, atIndex: 0)
sender.tableView.backgroundView = backgroundView
}

带有 UICollectionView 的 TableView 单元格:

enter image description here

最佳答案

我删除了那个视觉效果 View ,并通过向 collectionView 添加背景来实现相同的效果。闪烁的是视觉效果 View ,而不是单元格或其中的其他 View 。我通过编辑实现了与视觉效果 View 相同的效果:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

包括:

collectionView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.25)

关于ios - 使用 reloadRowsAtIndexPaths 或 reloadSections 导致 Tableview Cell 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33029150/

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