2

enter image description here

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)

    }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

2

In your storyboard, make sure that the segue is taken from VC1 to VC2 not from Button to VC2.

And the error you're getting is something different and has nothing to do with the segue. It's related to the firebase. You can checkout these threads:

Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments

Document references must have an even number of segments error on a collection reference

Firebase Invalid document reference. Document references must have an even number of segments

Soroush
  • 541
  • 4
  • 17
  • alright, agree with to handle the segue, but what about the firebase error, shall I provide some more code –  Oct 14 '19 at 08:40
  • Your question's title is why the segue is not performed. That is another question which you can open another thread for. @ramneek – Soroush Oct 14 '19 at 08:46
  • in `toComments` function, set a breakpoint under `post` variable and check if you're selecting the right one from your datasource. @ramneek – Soroush Oct 14 '19 at 09:00