CKAsset不会显示在tableview图像中
我有一个可选的图像在云端数据库(检查数据库和图像是在我添加到我的testing中的情况下)。 我创build了一个类,将logging字段初始化为我在tableview中使用的variables。 我也有一个自定义单元格。 但图像不会显示在我的自定义tableview单元格中。 我不知道是否有一个可选的图像在桌面视图图像导致问题,或者如果有我的代码/设置在cloudkit的问题。
任何帮助非常感谢,因为我已经坚持了一个多星期,并没有什么网上关于这个。
这是我的class级代码:
var feedResults = [UserPosts]() class UserPosts { var record: CKRecord var description: String var username: String //var image: CKAsset? // tried also initializing the CKAsset separately var postPic: UIImage? init(record: CKRecord) { self.record = record self.description = record.objectForKey("description") as String self.username = record.objectForKey("username") as String // self.image = record.objectForKey("postPic") as? CKAsset if var pic = record.objectForKey("postPic") as CKAsset! { self.postPic = UIImage(contentsOfFile: pic.fileURL.path!) // below is the other way I've seen it done. // var url = pic.fileURL! // var imageData = NSData(contentsOfFile: url.path!) // self.postPic = UIImage(data: imageData!) } }
}
这是我的tableview代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell let record = feedResults[indexPath.row] cell.postDescription.text = record.description cell.userName.text = record.username if record.postPic != nil { cell.postPic.image = record.postPic! } return cell }
我也见过一些将CKAsset拉入UIImage的方法。 第一种方式,就是我如何看待苹果在CloudKitAtlas项目中做的。 虽然我不熟悉Obj-C,但我认为我正确地遵循了它 – CloudKitAtlas示例
我也看到它使用NSData(contentOFFile :)和UIImage(data :)完成,如此处所示:这是CKAsset示例
尝试没有.paths和使用contentsOfURL。 这是我如何做到这一点(在你的CKAsset中):
if var data = NSData(contentsOfURL: pic!.fileURL) { self.postPic = UIImage(data: data!)! }
除此之外,你做一个dequeueReusableCellWithIdentifier,但不检查它是否返回零。 你应该创build一个新的单元格实例如果它是零
您可以像这样显示来自CKAsset的图像:
var img = record.valueForKey("Picture") as? CKAsset cell.imageView?.image = UIImage(contentsOfFile: img!.fileURL.path!)
希望这可以帮助!
- 未收到Mac上自定义logging区域的CloudKit推送通知
- CloudKit fetchRecordChangesOperation提供了一个“AppDefaultZone不支持同步语义”
- 我可以将CloudKit数据传输到新的容器吗?
- iOS swift:使用coredata(cloudkit)存储caching
- UPDATE通知的替代方法无效
- 您可以在不同应用程序之间共享CloudKit上的数据吗?
- 保存CloudKitlogging“未经身份validation”(9/1002)“”此请求需要经过身份validation的帐户“”
- CloudKit在不同的iCloud帐户之间共享数据,但不与所有人共享
- CKFetchNotificationChangesOperation有时不会返回UPDATE,DELETE通知