![](/img/trans.png)
[英]UICollectionView inside UITableViewCell: order of `reloadData` for each?
[英]iOS Swift ReloadData on UITableView does not refresh UICollectionView inside of UITableViewCell
我有一个 UITableView Controller 类,里面是一个 String 数组。 Table 视图有 1 个单元格原型,其中有一个 UICollectionView 和 1 个单元格原型。
CollectionView 通过将数组传递到 tableview 单元格来填充,这是一个 UICollectionView 委托和数据源。
当我对 TableViewController 内的数组进行更改并调用 self.tableView.reloadData() 时,单元格内的 CollectionView 不会更新。
我该如何解决?
谢谢
编辑:
TableViewController 中的代码:
@IBAction func addToArrayAction(sender: AnyObject) {
self.testArray.append("Ant-Man")
self.tableView.reloadData()
}
var testArray = ["Guardinas", "Iron Man", "Avengers", "Captain America"]
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("collectionContainerCell", forIndexPath: indexPath) as! TableViewCell
cell.testArray = self.testArray
return cell
}
UITableViewCell 中的代码:
var testArray: [String]?
override func awakeFromNib() {
super.awakeFromNib()
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("collectionViewCell", forIndexPath: indexPath) as! CollectionViewCell
cell.movieTitleLabel.text = self.testArray![indexPath.item]
cell.movieYearLabel.text = "2016"
return cell
}
请尝试在数组中的每次更新时调用UICollectionView
reloadData
。 如果您使用的是只有一个格UITableView
那么您可以在重装cellForRowAtIndexPath
方法UITableView
其他你能可以在调用后调用reloadData
的UITableView
。
添加 cell.collectionView.reloadData() 后,我的项目中的 CollectionView 滚动速度非常慢。 这样的问题怎么解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.