swift - 未加载 uicollectionview?

标签 swift uitableview uicollectionview

当我添加到 View 中时未加载collectionview并加载:

newsTableView.estimatedRowHeight = 44.0
newsTableView.rowHeight = UITableViewAutomaticDimension

但是如果删除此代码,我的集合将加载到单元格中。

此代码适用于表格 View 中的单元格

class UserAddFriends: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate {

@IBOutlet weak var friendsCollection: UICollectionView!
@IBOutlet weak var userPhoto: UIImageView!
let cellReuseIdentifier = "friendCell"
var listImageForFriendsCollection: [String]!

override func awakeFromNib() {
    super.awakeFromNib()
    friendsCollection.delegate = self
    friendsCollection.dataSource = self
    listImageForFriendsCollection = []
    userPhoto.circleImage()
}


func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    var cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellReuseIdentifier, forIndexPath: indexPath) as! NewsCollectionView
    cell.friendsPhoto.image = UIImage(named: listImageForFriendsCollection[indexPath.row])
    cell.friendsPhoto.circleImage()

    return cell
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return listImageForFriendsCollection.count
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 15
}

}

最佳答案

不幸的是,您的代码和描述缺乏上下文。

在我看来,好像您想在 UITableViewCell 中显示 UICollectionView。

如果将 UITableView 的 rowHeight 设置为 UITableViewAutomaticDimension,则必须确保 UITableViewCell 内的内容(即 UICollectionView)决定单元格的高度。您通常通过 Interface Builder 添加适当的约束来完成此操作。

关于swift - 未加载 uicollectionview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31764246/

相关文章:

ios - 相对于 iOS 中帧的初始引用的电话加速

ios - Collectionview 内部 tableview 单元格索引路径问题

ios - Swift: Collection View 未正确调整以更改大小

ios - Hashable == 方法无法快速检测两个对象之间的差异

ios - 在 Swift 和 iOS 支持中使用空字符串过滤 NSDictionary >= 8.0

ios - 在 Swift 中将 AVAudioPlayer 输出更改为扬声器?

ios - Xcode : This coder requires that replaced objects be returned from initWithCoder:

ios - 检查 JSON 值是否存在 - iOS

ios - 报告 UITableview reloadData 崩溃

uicollectionview - 发送到实例的无法识别的选择器中的问题