I'm trying to populate a label in my custom cell for my UITableViewController with information from my Firebase Database but I keep running into this error:
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
I did read this link: What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?
I don't think I'm accessing outlets before they're loaded in and I did check that my IBOutlet connection is correct.
class FeedCell: UITableViewCell {
@IBOutlet weak var postText: UILabel!
}
class FeedTableViewController: UITableViewController {
var postInfo = FeedCell()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
self.tableView.rowHeight = 100.0
// postText = UILabel()
//
var ref: DatabaseReference!
ref = Database.database().reference()
let cellRef = ref.child("post/body")
cellRef.observeSingleEvent(of: .value) { (snapshot) in
if let body = snapshot.value as? String {
self.postInfo.postText.text = body
print(body)
}
}
}
I expected the label to be updated with the body text "test firebase" but I'm just running into that error. Is it because I defined my IBOutlet in another class then referenced it in my FeedTableVIewController? Any advice would be appreciated!
cellForRowAtIndexPath
method you configure cell with the data – Latenec