当我添加到 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/