2017-04-14 98 views
1

這是我的第一篇文章放在這裏,所以請原諒我,如果我忘了張貼細節或兩個:)Swift3:didSelectRowAt推到Segue公司不叫

  1. 我成立了一個視圖控制器(故事板ID: 「SavedMemeVC」)
  2. 我需要從另一個包含表的VC繼續,但是點擊完全被忽略。你能幫忙嗎?

代碼如下:

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") 
    } 
} 

回答

1

您應該添加的tableview的delegate

override func viewDidLoad() { 
    super.viewDidLoad() 

    memeTable.delegate = self 
} 
+0

謝謝,這工作 – Starkus