2017-02-28 75 views
0

我配置動態細胞中使用的UITableViewCell控制器的表,我想執行賽格瑞點擊一個特定的點觸手勢時斯威夫特3 Segue公司中的UITableViewCell控制器

class PostCell: UITableViewCell { 

    @IBOutlet var actionComments: UIImageView! 

    var post: FeedPost! 

    let postID: String = "" 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 

     let tapGesture = UITapGestureRecognizer(target: self, action: #selector(likeTapped)) 
     tapGesture.numberOfTapsRequired = 1 

     actionLike.addGestureRecognizer(tapGesture) 
     actionLike.isUserInteractionEnabled = true 

     let commentGesture = UITapGestureRecognizer(target: self, action: #selector(goToComments)) 
     commentGesture.numberOfTapsRequired = 1 
     commentGesture.delegate = self 

     actionComments.addGestureRecognizer(commentGesture) 
     actionComments.isUserInteractionEnabled = true 

    } 

    func goToComments(sender: UITapGestureRecognizer) { 



    } 
} 

這是我PostCell類(有多餘的代碼我剛纔這個職位的緣故刪除),這是我的tableview這是我newsfeedvc

class NewsFeedVC: UIViewController, UITableViewDelegate, UITableViewDataSource { 

    @IBOutlet weak var tableView: UITableView! 

    var posts = [FeedPost]() 

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

     let post = posts[indexPath.row] 

     if let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as? PostCell { 

      cell.configureCell(post: post) 

      return cell 

     } else { 

      return PostCell() 

     } 

    } 

} 

我已經設置了SEGUE了IDENTIFER但我不能用在goToComments功能performsegue我postcell類?

+0

什麼阻止了你在'goToComments(sender:)'中使用'performSegue'?你有沒有在Storyboard中添加segue?應用程序崩潰了嗎?你會得到什麼錯誤信息?人們需要更多的細節來了解問題。 –

+0

@RoboticCat如果我添加'performSegue(withIdentifier:「goToComments」,發件人:無)'goToComments我得到'使用未解決的標識符' – Chad

+0

什麼未解決的標識符 - 你錯過了錯誤消息的部分應該指出什麼是不在範圍內。這應該全部添加到您的問題。另外,你是否在Stack Overflow中搜索了帶有相同錯誤信息的問題?有很多解決方案;你排除了什麼? –

回答

1

要解決您的問題,您有兩種選擇。

  1. 創建一個delegate/protocolNewsFeedVC實現它,並在裏面PostCell創建的實例。之後在cellForRowAt中設置delegate方法現在在goToComments中使用該委託並調用其在NewsFeedVC中實現的方法並在該方法內執行segue。

  2. 不要在awakeFromNib方法中添加手勢,而是在cellForRowAt方法中添加手勢,在NewsFeedVC中顯示其操作方法。現在你可以輕鬆地執行你的賽格。

+0

我無法將圖像添加到newsfeedvc作爲iboutlet,以便在cellForRowAt添加手勢? – Chad

+0

@Chad不明白你的意見,你能否解釋一下你的問題。 –

+0

所以我試圖通過在cellforRowAt中添加手勢來嘗試第二種解決方案,但這是在我的'NewsFeedVC'中,而awakeFromNib是'PostCell:UITableViewCell'類的一部分,如果我嘗試將圖像視圖添加到'NewsFeedVC'中,爲了添加手勢,我得到一個錯誤'插座無效。插座不能連接到重複數據# – Chad