【发布时间】:2018-04-13 21:46:43
【问题描述】:
我正在使用一个与 tableview 连接的 ViewController,并使用 ExpandableCell lib 来展开 UITableviewcell。
我在情节提要中使用 UICollectionview 创建了一个 expandcell,但是当我使用 dequeueReusableCell 时,他不会加载 UICollectionview
我正在使用 Swift 4 Xcode 9.2
这是我在 View Controller
的代码 override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(ServicesCell.self, forCellReuseIdentifier: "servicesCell")
self.tableView.register(ConciergeCell.self, forCellReuseIdentifier: "conciergeCollection")
}
extension ViewController : ExpandableDelegate {
func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]? {
let cell = tableView.dequeueReusableCell(withIdentifier: ConciergeCell.ID) as! ConciergeCell
return [cell]
}
extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return concierge.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.section {
cell.displayContent(image: concierge[indexPath.row].image!, title: concierge[indexPath.row].name!)
cell.backgroundColor = UIColor.dark70
cell.layoutSubviews()
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Collection view at row \(collectionView.tag) selected index path \(indexPath)")
}
UITableviewcell 类
class ConciergeCell: UITableViewCell {
static let ID = "conciergeCollection"
@IBOutlet weak var collectionView: UICollectionView!
}
UICollectionviewcell
class ConciergeCollectionCell: UICollectionViewCell {
@IBOutlet var mainImage: UIImageView!
@IBOutlet var mainLabel: UILabel!
func displayContent(image: UIImage, title: String) {
mainImage.image = image
mainLabel.text = title
}
}
我可以采取哪些措施来解决这个问题?我不知道是否有必要在 viewDidLoad 中注册 uitableviewcell,因为我是使用 Storyboard 创建的
【问题讨论】:
-
您是否为您的集合视图实例设置了委托和数据源?如果您可以将故事板的屏幕截图与插座连接一起包括在内,这也可能会有所帮助。
-
@Pranay 我用截图更新问题,我可以在哪里设置委托和数据源?
标签: ios swift uitableview uicollectionview