如果我想将一个img从collectionView分享到Facebook,我就崩溃了。我通过CocoaPods使用Facebook SDK for swift。 如果我理解正确,那么是我的图片NIL中的URL。但另一方面,如果我点击“myImage”,img就会被加载。嗯有什么不对?
import FacebookLogin
import FacebookShare
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.layer.borderColor = UIColor.purple.cgColor
cell?.layer.borderWidth = 2
let imageCell = collectionView.cellForItem(at: indexPath) as! imageCellCollectionViewCell
// let imageCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! imageCellCollectionViewCell
guard let myImage = imageCell.imageToShare.image else {
print("leer")
return
}
let photo = Photo(image: myImage, userGenerated: true)
let content = PhotoShareContent(photos: [photo])
do {
try ShareDialog.show(from: myController, content: content)
} catch {
print(error)
}
}
答案 0 :(得分:0)
您需要检查myController
对象。也许它是零:
if let vc = myController {
do {
try ShareDialog.show(from: vc, content: content)
} catch {
print(error)
}
}
如果在您的MyViewController中实现了集合View委托方法,那么您可以直接使用Self
这样:
do {
try ShareDialog.show(from: Self, content: content)
} catch {
print(error)
}
答案 1 :(得分:0)
这是答案;-) DAMN ...自我而不是vc。 任何人都可以向我解释一下吗?有什么区别?
do {
try ShareDialog.show(from: self, content: content)
} catch {
print(error)
}