D
D
Dima Grib2021-04-23 12:05:17
Swift
Dima Grib, 2021-04-23 12:05:17

How to handle didSelectRowAt in NSObject class and open View?

Greetings. Tell me who knows how to process didSelectRowAt correctly in NSObject and open the required View?

class NewsTableHandler: NSObject, UITableViewDataSource, UITableViewDelegate {

    
    var articles: [Article] = []
    var imageUrl: String = ""
    var images: [String] = [] 
    var jsonContainer: [Article] = []
    let newsView = NewsView()

    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell()
    }

    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("\n NewsCollectionHandler didSelectRowAt")
        let item = articles[indexPath.row]
        //let media = medias[indexPath.row]
        guard let url = URL(string: item.link ?? " ") else { return }
        newsView.url = url
        // UIApplication.shared.keyWindow?.rootViewController?.present(newsView, animated: true, completion: nil)
    }
    
    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vorobei, 2021-04-23
@ivanvorobei

Do you want to show the new controller? Most likely you need one of two methods:

// Present
self.present(UIViewController())

// Push (если родитель навигейшн)
self.navigationController?.pushViewController(UIViewController())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question