我正在开发一个应用程序,用户可以创建带有标题,描述,日期和图片的“内存”。单击“保存”后,内存将保存到用户的内存表视图中。如果用户未添加自己的图像,则有一个默认图片用于记忆。出于某种原因,这些内存已成功保存到Firebase数据库中,但是当用户提交登录到应用程序时,只有带有用户从其照片库添加的图片的内存才是 >未被添加到表视图中,并且具有默认应用程序图片的内存已成功添加到表视图中。
我不知道它是否重要,但是它说:
加载失败,错误为Error Domain = NSURLErrorDomain代码= -999“已取消” UserInfo
有人知道它为什么会发生吗,我该如何解决?
这是装载存储器功能:
func loadMemories()
{
let UID = Auth.auth().currentUser!.uid
// self.ref.child("MEmories").queryOrdered(byChild: "uid").queryEqual(toValue: userID).observe(.value, with: {
self.ref.child("MEmories").queryOrdered(byChild: "uid").queryEqual(toValue: UID).observe(.value, with: { snapShot in
if let dict = snapShot.value as? NSDictionary
{
for d in (dict as? Dictionary<String,AnyObject>)!
{
let title = d.value["title"] as?String
let body = d.value["body"] as? String
let uid = d.value["uid"] as? String
let imageRef = d.value["imageRef"] as? String
let date = d.value["date"] as? NSNumber
let m = Memory(title: title!, body: body!, uid: uid!,imageRef:imageRef!, date: date!)
m.key = d.key
let tempImageRef = self.sref.child(m.imageRef)
tempImageRef.getData(maxSize: 1*1024*1024, completion: {(data,error) in
if error == nil
{
if let imageData = data
{
m.image = UIImage(data: imageData)
self.memories.append(m)
self.tbl.reloadData()
}
}
})
}
// copy memories array to the filtered array
self.filteredArray = self.memories
self.tbl.reloadData()
}//end of if
self.ref.child("MEmories").removeAllObservers()
})
}
答案 0 :(得分:0)
将闭包中的if
更改为
//image closure
if let imageData = data {
m.image = UIImage(data: imageData)
self.memories.append(m)
}
...
//End of outer closure
self.filteredArray = self.memories
DispatchQueue.main.async {
self.tbl.reloadData()
}
答案 1 :(得分:0)
func loadMemories()
{
let UID = Auth.auth().currentUser!.uid
// self.ref.child("MEmories").queryOrdered(byChild: "uid").queryEqual(toValue: userID).observe(.value, with: {
self.ref.child("MEmories").queryOrdered(byChild: "uid").queryEqual(toValue: UID).observe(.value, with: {
snapShot in
if let dict = snapShot.value as? NSDictionary
{
for d in (dict as? Dictionary<String,AnyObject>)!
{
let title = d.value["title"] as?String
let body = d.value["body"] as? String
let uid = d.value["uid"] as? String
let imageRef = d.value["imageRef"] as? String
let date = d.value["date"] as? NSNumber
let m = Memory(title: title!, body: body!, uid: uid!,imageRef:imageRef!, date: date!)
m.key = d.key
let tempImageRef = self.sref.child(m.imageRef)
tempImageRef.getData(maxSize: 1*1024*1024, completion: {(data,error) in
print ("imageRef")
if error == nil
{
if let imageData = data
{
m.image = UIImage(data: imageData)
self.memories.append(m)
self.tbl.reloadData()
}
}
})
}
// copy memories array to the filtered array
self.filteredArray = self.memories
DispatchQueue.main.async {
self.tbl.reloadData()
}
}//end of if
self.ref.child("MEmories").removeAllObservers()
})
}