我试图使用reloadRowsAtIndexPaths
或reloadSections
来重新加载特定的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
}
带有TableView单元的UICollectionView:
发布于 2015-10-15 05:06:44
我删除了该视觉效果视图,并通过向collectionView添加一个背景来实现相同的效果。闪烁的是视觉效果视图,而不是单元格或其中的其他视图。我通过编辑实现了与视觉效果视图相同的影响:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
包括:
collectionView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.25)
发布于 2015-10-15 02:27:39
当更新UI以在主线程上调度和异步任务时,请记住:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
https://stackoverflow.com/questions/33029150
复制相似问题