[英]iOS Swift ReloadData on UITableView does not refresh UICollectionView inside of UITableViewCell
I have a UITableView Controller class, and inside of it is a String array.我有一个 UITableView Controller 类,里面是一个 String 数组。 The Table view has 1 cell prototype and in it a UICollectionView with 1 cell prototype. Table 视图有 1 个单元格原型,其中有一个 UICollectionView 和 1 个单元格原型。
The CollectionView is populated by passing the array into the tableview cell, which is a UICollectionView Delegate and DataSource. CollectionView 通过将数组传递到 tableview 单元格来填充,这是一个 UICollectionView 委托和数据源。
When I make changes to the array inside the TableViewController, and call self.tableView.reloadData(), the CollectionView inside the cell does NOT update.当我对 TableViewController 内的数组进行更改并调用 self.tableView.reloadData() 时,单元格内的 CollectionView 不会更新。
How do I fix this?我该如何解决?
Thank you谢谢
EDIT:编辑:
Code in TableViewController: 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
}
Code in UITableViewCell: 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
}
Please try to call reloadData
of UICollectionView
on every update in array.请尝试在数组中的每次更新时调用UICollectionView
reloadData
。 If you are using only one cell in UITableView
then you can reload in cellForRowAtIndexPath
method of UITableView
else you can can call after calling of reloadData
of UITableView
.如果您使用的是只有一个格UITableView
那么您可以在重装cellForRowAtIndexPath
方法UITableView
其他你能可以在调用后调用reloadData
的UITableView
。
After I added cell.collectionView.reloadData(), CollectionView scrolling is so slow in my project.添加 cell.collectionView.reloadData() 后,我的项目中的 CollectionView 滚动速度非常慢。 How to solved that kind of problem.这样的问题怎么解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.