在CollectionView中刷新数据不起作用Swift
问题描述:
我需要刷新集合视图时,从另一个视图segue,但它不起作用,它永远不会进入collectionView func?我在这里做错了什么吗?谢谢在CollectionView中刷新数据不起作用Swift
class AddViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var titleTextField: UITextField!
@IBOutlet weak var notesTextView: UITextView!
@IBOutlet weak var exerciseName: UILabel!
var collectionView: UICollectionView?
var listOfExerciseItems:NSMutableArray = NSMutableArray()
override func viewDidAppear(animated: Bool) {
self.collectionView?.reloadData()
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return listOfExerciseItems.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:colvwCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as colvwCell
cell.exerciseName.text = listOfExerciseItems[indexPath.row] as String
return cell
}
答
您必须将您的AddViewController设置为viewDidLoad中的代表和collectionView的数据源。
执行segue时,实际上并不需要reloadData。
我认为你的collectionView设置不正确。它应该是一个IBOutlet。