2016-07-23 7 views
1
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as! ComposeCell 
    cell.deletePictureSignal.subscribeNext { (response) -> Void in 
     print("delete picture") 
     let deleteIndex = (self.pictureView.indexPathForCell(cell)?.item)! 
     self.pictures.removeAtIndex(deleteIndex) 
     //   self.pictureView.reloadData() 
    } 
    cell.addPictureSignal.subscribeNext { (response) -> Void in 
     print("add picture") 
     self.selectedIndex = (self.pictureView.indexPathForCell(cell)?.item)! 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     self.presentViewController(imagePicker, animated: true, completion: nil) 
    } 
    return cell 
} 

I reloadData、この方法が再び実施されるに信号をサブスクライブ倍数に回避することができ、かつ信号が多くの時間をサブスクライブされますが、どのように私はそれを解決することができますし、一度だけ購読確保しますか?ReactiveCocoaは、どのように私はcollectionViewのセル

答えて

0

最後に、私は私の自己によってそれを解決... 私はこの

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as! ComposeCell 



    cell.deletePictureSigin.takeUntil(cell.rac_prepareForReuseSignal).subscribeNext { (response) -> Void in 
     print("delete Picture") 
     let deleteIndex:Int = (self.pictureView.indexPathForCell(cell)?.item)! 
     self.pictures.removeAtIndex(deleteIndex) 
     self.pictureView.reloadData() 
    } 

    cell.addPictureSigin.takeUntil(cell.rac_prepareForReuseSignal).subscribeNext { (response) -> Void in 
     print("add Picture") 
     self.selectedIndex = (self.pictureView.indexPathForCell(cell)?.item)! 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     self.presentViewController(imagePicker, animated: true, completion: nil) 
    } 


    if indexPath.item == pictures.count { 
     cell.image = nil 
    } else { 
     cell.image = pictures[indexPath.item] 
    } 
    return cell 
} 
のように、「takeUntil」の方法を使用します
関連する問題