swift uitableview uicollectionview tableviewcell tvos

swift - UICollectionView no se actualiza dentro de UITableViewCell



tvos (1)

En el código que proporciona, puedo ver que llamó a reloadData() para la vista de tabla raíz. Pero si desea actualizar una vista de colección, también debe llamar a reloadData() para cada fila que contenga una vista de colección dentro. Por ejemplo, puede hacerlo en el método func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell . Agregue la línea cell.myCollectionView.reloadData() al final de este método y espero que funcione para usted.

Estoy construyendo una aplicación de tvos . Actualmente estoy atascado en un problema en el que tengo una UITableView . Hay dos secciones de mi UITableView y cada sección tiene solo una fila. En ambas filas tengo un UICollectionView que se desplaza horizontalmente. En cada UICollectionViewCell hay una imageView que se usa para mostrar alguna imagen. aquí está la imagen de lo que estoy armando.

He establecido un identificador de reutilización por separado para las UITableViewCells . Sin embargo, tengo el mismo identificador de reutilización para UICollectionViewCells .

Ahora estoy obteniendo datos de la web. Al principio no hay datos, por lo que UITableView y UICollectionViews están vacíos. Tan pronto como los datos estén disponibles, llamo a tableView.reloadData() pero llamar a esta función no trae la nueva información a la vista de colección. ¿Puede alguien guiarme cómo puedo hacer que esto funcione?

Aquí está mi código para la clase UITableviewCell personalizada.

import UIKit class UIScrollingTableViewCell : UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate { @IBOutlet weak var myCollectionView: UICollectionView! //MARK: CollectionViewDelegate & DataSource func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { print("numberOfSectionsInCollectionView ") return 1 } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if self.reuseIdentifier == recentlyWatchCellId { return DataManager.sharedInstance.recentlyWatched.count } else{ return DataManager.sharedInstance.recentlyAdded.count; } } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("smallCollectionViewCell", forIndexPath: indexPath) as! MyCollectionViewCell var lesson = DataManager.sharedInstance.recentlyWatched[indexPath.row] if self.reuseIdentifier == recentlyAddedCellId { lesson = DataManager.sharedInstance.recentlyAdded[indexPath.row] } if let url = lesson.instructorImageUrl { cell.imageView.sd_setImageWithURL(NSURL(string: url), placeholderImage: UIImage(named: "categoryLessons")) } return cell } //MARK: Focus override func canBecomeFocused() -> Bool { return false } }

y aquí está algo de mi código para el UIViewController que tiene los métodos de fuente de datos para mi tableView. tableview es un @IBOutlet

//MARK: UITAbleViewDelegate & UITableViewDatasource func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { switch section { case RecentLessonSection.Recorded.rawValue: return NSLocalizedString("Recently Added", comment: "Recently Added") case RecentLessonSection.Watched.rawValue: return NSLocalizedString("Recently Viewed", comment: "Recently Viewed") default: return "" } } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 2; //return RecentLessonSection.Max.rawValue } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell : UIScrollingTableViewCell switch indexPath.section { case RecentLessonSection.Recorded.rawValue: cell = tableView.dequeueReusableCellWithIdentifier(recentlyAddedCellId, forIndexPath: indexPath) as! UIScrollingTableViewCell case RecentLessonSection.Watched.rawValue: cell = tableView.dequeueReusableCellWithIdentifier(recentlyWatchCellId, forIndexPath: indexPath) as! UIScrollingTableViewCell default: cell = tableView.dequeueReusableCellWithIdentifier(recentlyWatchCellId, forIndexPath: indexPath) as! UIScrollingTableViewCell } return cell } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1; } //MARK : Notification Handlers func receivedNewData() { self.tableView.reloadData() }