2015-07-24 4 views
1

Я пытаюсь получить изображения из синтаксического анализа и отобразить их в виде коллекции. Xcode дает мне, что я не могу вызывать dequeueReusableCellWithReuseIdentifier с строкой типа аргумента.
У меня также есть сообщение о том, что SingleRowCell не конвертируется в UICollectionView. Неверна ли моя реализация Collection View? Я смог сделать это, используя табличное представление. Спасибо.Не удается получить изображения из Parse с помощью Collection View

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; 
    } 

} 

UPDATE

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) 
     }}} 

ответ

1

Firstlly, зарегистрировать класс для ячейки CollectionView:

self.collectionView!.registerClass(SingleRowCell.self, forCellWithReuseIdentifier: "mySingleCell") 

Затем в методе cellForItemAtIndexPath,

let singleCell: SingleRowCell = collectionView.dequeueReusableCellWithReuseIdentifier("mySingleCell", forIndexPath: indexPath) as! SingleRowCell 

// config the cell 

return singleCell 
+0

Благодарим Вас за быстрый ответ. Где вы регистрируете класс для ячейки коллекции? – Satsuki

+0

@ Satsuki В месте, где вы создаете свою коллекциюView. Где-то вроде 'viewDidLoad' вашего ViewController. – liushuaikobe

+0

Я добавил его в ViewDidLoad, но он хочет! рядом с представлением коллекции. У меня все еще есть ошибка с возвратом singleCell – Satsuki

Смежные вопросы