は、XcodeのiOSの迅速UICollectionviewcellは、スナップショットのエラー
fatal error: unexpectedly found nil while unwrapping an Optional value
please click here for screenshot of that error
をスローしますは、ここに私の機能
func screenshotBSCell() {
//Create the UIImage
UIGraphicsBeginImageContext(CGSizeMake(bsCell.bounds.size.width, bsCell.bounds.size.height))
***self.bsCell.layer.renderInContext(UIGraphicsGetCurrentContext()!)***
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
//share the image to Social Media
let composeSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
composeSheet.setInitialText("Hello, Facebook!")
composeSheet.addImage(image)
presentViewController(composeSheet, animated: true, completion: nil)
}
self.bsCellインスタンスをデバッグしてチェックしますか? – Surjeet
アプリがself.bsCell.layer.renderInContext((UIGraphicsGetCurrentContext())行でクラッシュする) –
'screenshotBSCell'はどこで呼び出されますか?問題は、 'UIGraphicsGetCurrentContext()'がnilを返し、強制的にアンラップ(そうしないでください:)してクラッシュすることです。だから... 'UIGraphicsBeginImageContext'へのあなたの呼び出しが期待通りに動作しないようです。 @Surjeetが示唆しているように、あなたの 'bsCell'がnilでないことを確認し、' bsCell'のサイズを確認して、それが有効であることを確認してください。 – pbodsk