我正在尝试在swift中创建一个消息传递应用程序。但我在创建自定义tableview单元格时遇到错误,我不知道如何解决这个问题。我创建了2个自定义单元格,我正在检查代码中我必须使用的单元格。
代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let uid = FIRAuth.auth()?.currentUser?.uid
let ref = FIRDatabase.database().reference()
let uidReference = ref.child("Users").child(uid!)
uidReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let message = self.messages[indexPath.row]
if message.Sender == dictionary["Username"] as? String {
let cell = self.messagesTableView.dequeueReusableCell(withIdentifier: "otherMessageCell") as! OtherMessageTableViewCell
let message = self.messages[indexPath.row]
cell.sender.text = message.Sender
cell.message.text = message.Message
let uid = FIRAuth.auth()?.currentUser?.uid
let ref = FIRDatabase.database().reference()
let uidReference = ref.child("Users").child(uid!)
uidReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
if(message.Sender! == dictionary["Username"]! as! String) {
cell.sender.textAlignment = .right
cell.message.textAlignment = .right
}else{
cell.sender.textAlignment = .left
cell.message.textAlignment = .left
}
}
}, withCancel: nil)
let usernameReference = ref.child("Usernames").child(message.Sender!)
usernameReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let uid = dictionary["UID"] as! String
let uidReference = ref.child("Users").child(uid)
uidReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let imageLink = dictionary["Image Link"] as! String
cell.profileImage.loadImageWithURLString(urlString: imageLink)
}
}, withCancel: nil)
}
}, withCancel: nil)
return cell
}else{
let cell = self.messagesTableView.dequeueReusableCell(withIdentifier: "selfMessageCell") as! SelfMessageTableViewCell
let message = self.messages[indexPath.row]
cell.sender.text = message.Sender
cell.message.text = message.Message
let uid = FIRAuth.auth()?.currentUser?.uid
let ref = FIRDatabase.database().reference()
let uidReference = ref.child("Users").child(uid!)
uidReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
if(message.Sender! == dictionary["Username"]! as! String) {
cell.sender.textAlignment = .right
cell.message.textAlignment = .right
}else{
cell.sender.textAlignment = .left
cell.message.textAlignment = .left
}
}
}, withCancel: nil)
let usernameReference = ref.child("Usernames").child(message.Sender!)
usernameReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let uid = dictionary["UID"] as! String
let uidReference = ref.child("Users").child(uid)
uidReference.observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let imageLink = dictionary["Image Link"] as! String
cell.profileImage.loadImageWithURLString(urlString: imageLink)
}
}, withCancel: nil)
}
}, withCancel: nil)
return cell
}
}
}, withCancel: nil)
}
我得到的错误是:void函数中出现意外的非void返回值。
我希望有人可以帮助我,谢谢!