Ios Can';t使用集合视图从解析接收图像
我试图从解析中检索图像并将其显示到集合视图。Xcode告诉我不能用参数类型字符串调用Ios Can';t使用集合视图从解析接收图像,ios,swift,parse-platform,uicollectionview,Ios,Swift,Parse Platform,Uicollectionview,我试图从解析中检索图像并将其显示到集合视图。Xcode告诉我不能用参数类型字符串调用dequeueReusableCellWithReuseIdentifier。 我还有一个错误,告诉我,SingleRowCell不能转换为UICollectionView。我的集合视图实现是否不正确?我可以使用表视图来完成这项工作。多谢各位 override func collectionView(collectionView: UICollectionView, cellForItemAtIndexP
dequeueReusableCellWithReuseIdentifier
。我还有一个错误,告诉我,
SingleRowCell
不能转换为UICollectionView
。我的集合视图实现是否不正确?我可以使用表视图来完成这项工作。多谢各位
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let singleCell:SingleRowCell = collectionView.dequeueReusableCellWithReuseIdentifier("mySingleCell")as! SingleRowCell
singleCell.radLabel.text = imageText [indexPath.row]
imageFiles[indexPath.row].getDataInBackgroundWithBlock{
(imageData: NSData?, error: NSError?) -> Void in
if imageData != nil {
let image = UIImage(data: imageData!)
singleCell.radImageView.image = image
}else {
println(error)
}}
return mysingleCell
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 20;
}
}
更新
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView!.registerClass(SingleRowCell.self, forCellWithReuseIdentifier: "mySingleCell")
// Do any additional setup after loading the view.
var query = PFQuery(className: "rad")
query.whereKey("uploader", equalTo: PFUser.currentUser()!)
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock{
(posts: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
for post in posts!{
self.imageFiles.append(post["imageFile"]as! PFFile)
self.imageText.append(post["imageText"]as! String)
}
println(self.imageFiles.count)
self.topsCollectionView.reloadData()
} else {
println(error)
}}}
首先,为CollectionView的单元格注册一个类:
self.collectionView!.registerClass(SingleRowCell.self, forCellWithReuseIdentifier: "mySingleCell")
然后,在cellForItemAtIndexPath
方法中
let singleCell: SingleRowCell = collectionView.dequeueReusableCellWithReuseIdentifier("mySingleCell", forIndexPath: indexPath) as! SingleRowCell
// config the cell
return singleCell
谢谢你的快速回答。在何处为Collection View的单元格注册类?@Satsuki在初始化collectionView的位置。类似于ViewController的
viewDidLoad
的地方。我已经在viewDidLoad中添加了它,但它想要的是!在“集合”视图旁边。我仍然有一个返回错误singleCell@Satsuki您的SingleRowCell
应该是UICollectionViewCell
的子类,并且您应该添加一个代码>在collectionView之后。我编辑了我的代码。谢谢你发现了错误,但应用程序仍然崩溃3347.44.2/UICollectionViewController.m:171 2015-07-24 16:43:16.495设计师[2252:993949]***由于未捕获异常“NSInternalInconsistencyException”,终止应用程序,原因:'-[UICollectionViewController loadView]加载了“4H1-83-9jU-view-Mo7-Ik-xix”nib,但未获得UICollectionView。“
您可以查看我的代码我已更新了问题