Swift 反应可可如何避免在collectionView';s细胞
当我重新加载数据时,这种方式将再次实现,并且信号将被多次订阅,如何解决它并确保只订阅一次?最后,我自己解决它。。。 我用“takeUntil”的方式,像这样Swift 反应可可如何避免在collectionView';s细胞,swift,reactive-cocoa,reactive-cocoa-4,Swift,Reactive Cocoa,Reactive Cocoa 4,当我重新加载数据时,这种方式将再次实现,并且信号将被多次订阅,如何解决它并确保只订阅一次?最后,我自己解决它。。。 我用“takeUntil”的方式,像这样 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReus
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
}
最后,我自己解决了。。。 我用“takeUntil”的方式,像这样
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
}