IOS Swift UIActivityViewController可以共享文本,但不能在图像中的图像
问题描述:
我有一个UITableView具有文本和图像。我可以分享文字,但是由于零值而导致图像崩溃。这些图像已经下载,但似乎我不能让他们的工作,这是我的代码IOS Swift UIActivityViewController可以共享文本,但不能在图像中的图像
@IBAction func shareMyAction(_ sender: UIButton) {
let message = streamsModel.posting[sender.tag]
if streamsModel.stream_image_string[sender.tag].characters.count > 6 {
// Has image
let cell = sender.superview?.superview as? SocialCellView
if cell == nil {
print("cell is nil")
}
let myImage = cell?.stream_image.image
if myImage == nil {
print("myImage is NIL")
}
activityViewController = UIActivityViewController(activityItems: [streamsModel.Posts[sender.tag].appending(message) as NSString,myImage!], applicationActivities: nil)
} else {
activityViewController = UIActivityViewController(activityItems: [streamsModel.Posts[sender.tag].appending(message) as NSString], applicationActivities: nil)
}
}
在上面的代码,我也得到细胞和MYIMAGE为零。再次,图像显示在TableView上,但似乎无法让它们与UIActivityViewController一起使用。
答
基于您的评论,你的按钮是你的直接,你的问题是关系到这一行,所以你需要我在以前的评论说修改代码以这一个let cell = sender.superview?.superview as? SocialCellView
要添加一个额外的上海华
@IBAction func shareMyAction(_ sender: UIButton) {
let message = streamsModel.posting[sender.tag]
if streamsModel.stream_image_string[sender.tag].characters.count > 6 {
// Has image
let cell = sender.superview as? SocialCellView
if cell == nil {
print("cell is nil")
}
let myImage = cell?.stream_image.image
if myImage == nil {
print("myImage is NIL")
}
activityViewController = UIActivityViewController(activityItems: [streamsModel.Posts[sender.tag].appending(message) as NSString,myImage!], applicationActivities: nil)
} else {
activityViewController = UIActivityViewController(activityItems: [streamsModel.Posts[sender.tag].appending(message) as NSString], applicationActivities: nil)
}
}
希望这会有所帮助
您的按钮位于单元格上的视图上,还是直接位于单元格上? –
你可以发布你的细胞类吗?我认为你可以使用闭包,并且对你所尝试的更好 –
我的按钮直接在单元上。哦,好吧,我现在要做的 – user1591668