I am able to retrieve the posts in segment control as per the below ref, there is the comment button in the posts cell, upon clicking it gives this error of "Document references must have an even number of segments, but posts has 1'"
the screenshot of the screen also attached here
I checked many similar questions all they pointed to the document reference error, but if doc ref is wrong then how it is retrieving the list in tableview and giving error upon clicking the button.
let postsRef = Firestore.firestore().collection("posts").whereField("post_author_id", isEqualTo: Auth.auth().currentUser!.uid
).whereField("l3", isEqualTo: false).limit(to: 50)
cell code
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! PostCell
switch segmentControl.selectedSegmentIndex{
case 0:
cell.Mpost1 = post1[indexPath.row]
cell.commentbutton.tag = indexPath.row
cell.commentbutton.addTarget(self, action: #selector(toComments(_:)), for: .touchUpInside)
break
case 1:
cell.Mpost2 = post2[indexPath.row]
break
default:
break
}
return cell
}
@objc func toComments(_ sender: AnyObject) {
let commentbutton = sender as! UIButton
let post = pendingPost[commentbutton.tag]
postKey = post._documentId // or what key value it is
print("hello")
performSegue(withIdentifier: "toCommentsList2", sender: self)
}