Ios ';尝试将第0行插入节0,但在更新';
试图获取firebase中存储的图像并在tableview中显示,但显示错误 “未捕获的异常'NSInternalInconsistencyException',原因: '尝试将第0行插入节0,但该节中只有0行 更新“”后的第0节 用于上载图像的ImageUpload方法的代码:-Ios ';尝试将第0行插入节0,但在更新';,ios,swift,firebase,firebase-realtime-database,Ios,Swift,Firebase,Firebase Realtime Database,试图获取firebase中存储的图像并在tableview中显示,但显示错误 “未捕获的异常'NSInternalInconsistencyException',原因: '尝试将第0行插入节0,但该节中只有0行 更新“”后的第0节 用于上载图像的ImageUpload方法的代码:- class imageUpload { var imageDownloadUrl:String? private var image :UIImage! var label1:String! var label2:S
class imageUpload
{
var imageDownloadUrl:String?
private var image :UIImage!
var label1:String!
var label2:String!
var label3:String!
var label4:String!
init(image:UIImage,label1:String,label2:String,label3:String,label4:String) {
self.image = image
self.label1 = label1
self.label2 = label2
self.label3 = label3
self.label4 = label4
}
init(snapshot: DataSnapshot) {
let json = JSON(snapshot.value)
self.imageDownloadUrl = json["imgDownloadURL"].stringValue
self.label1 = json["label1"].stringValue
self.label2 = json["label2"].stringValue
self.label3 = json["label3"].stringValue
self.label4 = json["label4"].stringValue
}
func upload()
{
//1.new Database Refrence
let newImg = Database.database().reference().child("CameraPhoto").childByAutoId()
let newImgKey = newImg.key
//convert image into data
if let imgData = self.image.jpegData(compressionQuality: 0.6){
//2.new Storage Refrence
let ImgStorageRef = Storage.storage().reference().child("images")
let newImgRef = ImgStorageRef.child(newImgKey!)
//save the image into storage
newImgRef.putData(imgData).observe(.success) { (snapshot) in
//save the label and downloadURL()
snapshot.reference.downloadURL(completion: { (url, error) in
self.imageDownloadUrl = url?.absoluteString
let newImgDictionary = [
"imgDownloadURL" :self.imageDownloadUrl,
"label1":self.label1,
"label2":self.label2,
"label3":self.label3,
"label4":self.label4
]
newImg.setValue(newImgDictionary)
})
}
}
}
}使用以下方法:
self.tableVC.beginUpdates()
self.tableVC.insertRows(at: [indexpath], with: .top)
self.tableVC.endUpdates()
你能为你的
imageUpload
添加构造器的代码吗?图像上传成功并且能够下载URL请显示imageUpload
的代码。由于插入新行时计数为0,因此新图像似乎没有插入到数组中。插入到图像后,newImage
可能是nil
。请打印出图像。计数
,以确保图像在插入到显示的表格之前成功添加到图像数组。图像已添加到图像数组
self.tableVC.beginUpdates()
self.tableVC.insertRows(at: [indexpath], with: .top)
self.tableVC.endUpdates()