Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 我无法将firebase数据库中的子值放入tableview单元格中的标签框中_Swift_Firebase_Firebase Realtime Database - Fatal编程技术网

Swift 我无法将firebase数据库中的子值放入tableview单元格中的标签框中

Swift 我无法将firebase数据库中的子值放入tableview单元格中的标签框中,swift,firebase,firebase-realtime-database,Swift,Firebase,Firebase Realtime Database,我正在做一个项目,它有firebase数据库和swift。我有它,用户可以发布帖子(这是我的个人应用,主要是一个有趣的项目),然后上传到表视图上。但是在tableview单元格内,我有一个标签,标签上的名称应该放在哪里。它是一个自定义的表视图单元格。我也把它设置好了 问题在于,当我尝试将作者姓名放入标签单元格时。我试过很多东西。。。我想不出来 我的代码中有两个类。我知道这可能不是最好的编码实践,我的代码也可能不是最好的——但我正在学习 导入UIKit 进口火基 导入FirebaseAuth 导入

我正在做一个项目,它有firebase数据库和swift。我有它,用户可以发布帖子(这是我的个人应用,主要是一个有趣的项目),然后上传到表视图上。但是在tableview单元格内,我有一个标签,标签上的名称应该放在哪里。它是一个自定义的表视图单元格。我也把它设置好了

问题在于,当我尝试将作者姓名放入标签单元格时。我试过很多东西。。。我想不出来

我的代码中有两个类。我知道这可能不是最好的编码实践,我的代码也可能不是最好的——但我正在学习

导入UIKit
进口火基
导入FirebaseAuth
导入FirebaseDatabase
让userID=Auth.Auth().currentUser?.uid
var currentuser:String=“”
类TweetViewController:UIViewController、UITableViewDelegate、UITableViewDataSource{
var authornamerence:String=“”
var timelinepost:[字符串]=[]
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回timelinepost.count
}
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
让cell=tableView.dequeueReusableCell(标识符为“cell”,for:indexPath)作为!TweetTableViewCell
cell.postcontenttext.text=self.timelinepost[indexPath.row]
cell.postauthorlabel.text=self.authornamereference
返回单元
}
func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){
取消选择行(at:indexPath,动画:true)
}
@ibvar mytableview:UITableView!
func alertcreated(标题:字符串,消息:字符串){
let alert=UIAlertController(标题:标题,消息:消息,首选样式:。警报)
addAction(UIAlertAction)(标题:“确定”,样式:。默认,处理程序:{(操作)在
警报。解除(动画:真,完成:零)
}))
self.present(警报、动画:true、完成:nil)
}
@IBVAR名称标签:UILabel!
var-ref:DatabaseReference!
让userID=Auth.Auth().currentUser?.uid
var possstkeystring:String=“作者姓名”
重写func viewDidLoad(){
super.viewDidLoad()
posstKeyString=“作者”
ref=Database.Database().reference()
ref.child(“用户”).child(用户ID!)。在中观察(.value){(快照)
让userinfo=snapshot.value为?NSDictionary
让username=userinfo![“Name”]作为!字符串
self.namelab.text=用户名
self.namelab.font=UIFont(名称:“Bodoni 72小号”,大小:25)
currentuser=self.namelab.text!
}
self.ref.child(“All Post”).observe(DataEventType.childAdded){(snapshot)in
如果let item=snapshot.value as?NSDictionary{
var keyvalues:[字符串:任意]=[:]
keyvalues=[“发布内容”:项[“发布内容”]如有]
self.timelinepost.append(keyvalues[“Post Content”]as!String)
self.mytableview.reloadData()
}
self.ref.child(“All Post”).child(self.possstkeystring).child(“Post Author”).observe(DataEventType.value),在
如果let item=snapshot.value as?NSDictionary{
self.authornamereference=项目[“Post Author”]作为!字符串
}
})
}
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
self.view.endEditing(true)
}
@iAction func addtweet(uSender:ui按钮){
PerformScheue(标识符为“addnewpostsegue”,发件人:self)
}    
}
类TestAddPost:UIViewController{
重写func viewDidLoad(){
super.viewDidLoad()
}
@IBVAR postbuttonoutlet:UIButton!
@iAction func cancelbacktotimeline(u发件人:ui按钮){
self.performsgue(带有标识符:“cancelpost”,发件人:self)
}
var officialpostkeyvalue=“”
@iAction func postbuttonaddpost(u发件人:UIButton){
var-ref:DatabaseReference!
ref=Database.Database().reference()
让postvalue=ref.child(“所有Post”).childByAutoId()
让postkeyvalue=postvalue.key!
postvalue.child(“Post内容”).setValue(postcontent.text)
postvalue.child(“Post Author”).setValue(currentuser)
officialpostkeyvalue=postkeyvalue
self.performsgue(标识符为“addpostbacktotimeline”,发送者为self)
}
覆盖功能准备(对于segue:UIStoryboardSegue,发送方:有吗?){
让tabCtrl=segue.destination为!UITabBarController
让tweetviewcontroller=tabCtrl.ViewController![0]作为!tweetviewcontroller
tweetviewcontroller.PosstKeyString=officialpostkeyvalue
}
@IBOutlet弱var postcontent:UITextView!
}
我知道我的变量名不是传统的,或者我编程的方式可能不是最好的,但它的工作方式是我想要的,只是作者名不起作用

我是如何设置的:

当用户单击post-->时,它将使用我拥有的名称标记并将其存储为作者。然后,它将以树格式存储在firebase数据库中 “所有帖子”->随机ID->作者姓名 “所有帖子”->随机ID->帖子内容

然后我尝试检索作者姓名并将其放入标签中,我所做的一切都不起作用。请帮助