Push a second Controller

Viewed 34

I have follow Codelines to insert Data to a Tableview.

The Problem is that i can use here a segle / perfornsegue.

Have somebody a idea how i Push a second Controller when a User tappen the commentButton ??

I have also already searched Google for how I could approach this.

But since I'm still a beginner, I can't find a solution to the problem of calling up the second controller.

import UIKit
import FirebaseFirestore

@objc class PostTableViewDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
    
    private let posts: LocalCollection<Post>
    
    public init(posts: LocalCollection<Post>) {
        self.posts = posts
    }
    
    public convenience init(query: Query, updateHandler: @escaping ([DocumentChange]) -> ()) {
        let collection = LocalCollection<Post>(query: query, updateHandler: updateHandler)
        self.init(posts: collection)
    }
    
    public func startUpdates() {
        posts.listen()
    }
    
    public func stopUpdates() {
        posts.stopListening()
    }
    
    subscript(index: Int) -> Post {
        return posts[index]
    }
    
    public var count: Int {
        return posts.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: Constants.TableView.postTableViewCell, for: indexPath as IndexPath) as! PostTableViewCell
        let post = posts[indexPath.row]
        
        cell.commentButton.addTarget(self, action: #selector(tapped), for: .touchUpInside)
       
        //cell.button.addTarget(self, action: #selector(tapped), for: .touchUpInside)
        cell.populate(post: post)
        
        return cell
    }
    
    @objc func tapped() {
        print("Print User touch Button")

       // Jump here to the second Controller 
      
    }
1 Answers
Related