Problem with Segue

I'm stuck in a problem: I have a project with a lot of segues and vc's. After I was changing some ViewController to a TableViewController the segue to this won't work anymore. I created a blank TableViewController from Cocoa-Class as Subclass of UITableViewController. I'm using Storyboard and IB.

In HomeViewController I have a tableView. The Cell has a protocol HomeTableViewCellDelegate with some functions. One of them is didTapPostImage(post: PostModel). In the Cell I set a tapGesture to the PostImage:

func addTapGestureToPostImage(){
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTapPost))
        postImageView.isUserInteractionEnabled = true
        postImageView.addGestureRecognizer(tapGesture)
        print("TEMP -> TapGesture active")
    } 
    @objc func handleTapPost(){
        guard let post = post else { return }
        print("TEMP -> post image clicked")
        delegate?.didTapPostImage(post: post)
    }

In awakeFromNib I call the function of course.

In the HomeViewController I have an extension

extension NewsFeedViewController: HomeTableViewCellDelegate {
    func didTapPostImage(post: PostModel) {
        self.post = post
        performSegue(withIdentifier: "HomeToSinglePostViewController", sender: self)
        print("TEMP -> performSegue")
    }
} 

and I'm overriding prepare like:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "HomeToSinglePostViewController" {
            print("TEMP -> prepare")
            let singlePostVC = segue.destination as! SinglePostViewController
            singlePostVC.post = self.post
        }
    }

I've tried to rename the segue identifier - but that don't work, too. In prepare and in the extension I have some other segues to other vc's that all are working. When I navigate to another VC to access the new SinglePostViewController the segue doesn't work, too. The SinglePostViewController is unreachable from everywhere - but I get no error or hint.

In my log I can see that TapGesture, prepare-part and perform-part are called!

Before I created the TableViewController with class it was a ViewController with a ScrollView and a TableView inside - with that all was fine! What I'm missing? Tried so many things but no luck!

My HomeViewController is nested in a Navigation Controller - the SinglePostViewController not ( but the old one wasn't, too )

Hope someone has an answer. I'm using Xcode 14.2 with Swift 5 - InterfaceBuilder Project.

Kind regards and thanks in advance!

You don't show all the classes, so hard to tell. Just trying to understand from the explanations is really too confusing.

  • So explain clearly and synthetically what is the setup is ?
  • Do you get the prints in log ?
            print("TEMP -> prepare")
  • Move the print before performSegue:
        print("TEMP -> performSegue")
        performSegue(withIdentifier: "HomeToSinglePostViewController", sender: self)
  • How is SinglePostViewController defined ?

After I was changing some ViewController to a TableViewController

Which ViewController ? Could you show the related segue ?

Did you do a Clean Build Folder after the change ?

Thanks for reply.

After I setup here and there I found out that a class to auto height the table view header to fit a label was the problem. Next step is to find out what's wrong there but for now it's working.

override func viewDidLayoutSubviews(){
        super.viewDidLayoutSubviews()
        sizeHeaderToFit()
    }

    func sizeHeaderToFit(){
        guard let headerView = tableView.tableHeaderView else { return }
        headerView.setNeedsLayout()
        headerView.layoutIfNeeded()
        let height = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
        var frame = headerView.frame
        frame.size.height = height - 412
        headerView.frame = frame
        tableView.tableHeaderView = headerView
    } 

Here the 412 stands for all items (height) in the header together except the textfield.

The header was assigned to class "TableViewHeaderSinglePost" wich contains:

class TableViewHeaderSinglePost: UIView {
    @IBOutlet var postTextLabel:UILabel!

    override func layoutSubviews() {
        super.layoutSubviews()
        postTextLabel.preferredMaxLayoutWidth = postTextLabel.bounds.width
    }
}

If someone sees the problem please let me know ;-)

Thanks so far for helping me! Kind regards

Problem with Segue
 
 
Q