【发布时间】:2016-01-30 23:56:17
【问题描述】:
我正在使用 UICollectionrView 来显示视频。一切正常,除了我收到警告说:
2015-10-30 14:00:39.893 测试[6451:90574] 的行为 UICollectionViewFlowLayout 没有定义,因为:
2015-10-30 14:00:39.893 test[6451:90574] 项目宽度必须小于 比 UICollectionView 的宽度减去左边的部分插入 和右值,减去内容插入左值和右值。
2015-10-30 14:00:39.893 测试[6451:90574] 相关 UICollectionViewFlowLayout 实例是,并且它附加到;层 = ;内容偏移:{0, 0}; contentSize: {320, 0}> 集合 视图布局:。
2015-10-30 14:00:39.894 test[6451:90574] 在 UICollectionViewFlowLayoutBreakForInvalidSizes 在 调试器。
仅当我在 collectionView 中重新加载数据时才会出现此警告。
我已尝试更改宽度,但警告仍然存在。
我做错了什么?
var UserVideosInfo = [[String]]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "reloadCollectionVideoView:",
name: "ReloadCollectionVideoView",
object: nil)
}
@objc func reloadCollectionVideoView(notification: NSNotification) {
UserVideosInfo = NSUserDefaults.standardUserDefaults().objectForKey("UserVideosJSON") as! [[String]]
print(UserVideosInfo)
collectionView?.reloadData()
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if UserVideosInfo.count == 0 {
return 0
}else{
return UserVideosInfo.count
}
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let videoCell = collectionView.dequeueReusableCellWithReuseIdentifier("VideoCell", forIndexPath: indexPath) as UICollectionViewCell
let communityViewController = storyboard?.instantiateViewControllerWithIdentifier("community_id")
videoCell.frame.size.width = (communityViewController?.view.frame.size.width)!
videoCell.center.x = (communityViewController?.view.center.x)!
return videoCell
}
【问题讨论】:
-
这篇文章解释了为什么会发生这种情况并给出了解决方案:stackoverflow.com/a/39497850/4218640
标签: ios xcode uicollectionview swift2