Starkus
Starkus

Reputation: 157

Swift3: didSelectRowAt push to segue not called

this is my first post on here, so please forgive me if I forget to post a detail or two:)

  1. I set up a View Controller (Storyboard ID: "SavedMemeVC")
  2. I need to segue from another VC that contains a table, however the tap is completely ignored. Can you please help?

Code is below:

import UIKit
import Foundation

class MemeTableVC: UIViewController, UITableViewDataSource, UITableViewDelegate, UINavigationControllerDelegate {
    @IBOutlet weak var memeTable: UITableView!
    var memes : [Meme]!

    override func viewWillAppear(_ animated: Bool) {
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        memes = appDelegate.memes
        self.memeTable.reloadData()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

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

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MemeCell")!
        let memeListItem = memes[(indexPath as NSIndexPath).row]
        cell.textLabel?.text = "\(memeListItem.topText!)"
        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let detailController = self.storyboard!.instantiateViewController(withIdentifier: "SavedMemeVC") as! SavedMemeVC
        let meme = memes[(indexPath as NSIndexPath).row]
        detailController.memeImage = meme.memedImage
        self.navigationController!.pushViewController(detailController, animated: true)
        print("something")
    }
}

Upvotes: 1

Views: 130

Answers (1)

Luan Tran
Luan Tran

Reputation: 1142

You should add delegate of tableview

override func viewDidLoad() {
   super.viewDidLoad()

   memeTable.delegate = self
}

Upvotes: 1

Related Questions