2017-08-09 27 views
0

在圖像視圖敲擊在我的Xcode項目製作SEGUE我想在在的tableview細胞圖像上輕敲創建SEGUE。我搜索周圍的答案,最相關的是將圖像視圖更改爲按鈕。這個解決方案很遺憾,因爲我已經以某種方式我要爲當一個圖像是在其定製的圖像看法不符合我的項目。來自小區

所以,現在我在急需幫助。我有一個按鈕,在另一個單元格中執行與我想要的相同的搜索。它讓我把該單元格,並追加到一個全局變量,所以當其他視圖顯示的objectID,它將採取的objectID,並做必要的功能。我抄代碼低於按鈕:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as! Cell1 
    cell.textButton.layer.setValue(indexPath, forKey: "index") 
    return cell 
} 

@IBAction func textPressed(_ sender: Any) { 
    let index = (sender as AnyObject).layer.value(forKey: "index") as! IndexPath 

    let cell = tableView.cellForRow(at: index) as! Cell1 

    globalText.append(cell.objectID) 
    let text = self.storyboard?.instantiateViewController(withIdentifier: "TextVC") as! TextVC 
    self.navigationController?.pushViewController(text, animated: true) 
} 

現在我只需要知道如何做到這一點同樣的事情,但對於小區內的ImageView的。有人可以幫忙嗎?

+0

「在另一個單元格中有一個帶有文本的按鈕「是否與帶有圖像的單元格有任何關係?如果沒有,只是靜態地創建單元格,使用按鈕點擊 – Saranjith

回答

1

從您的視圖控制器創建SEGUE到目的地,並給它一個 「標識符」,那麼

在細胞用於行

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(viewImage(_:))) 
imageView.isUserInteractionEnabled = true 
imageView.tag = tag! 
imageView.addGestureRecognizer(gesture) 

創建函數來執行賽格瑞

func viewImage(_ sender: AnyObject) { 
    let tag = sender.view.tag 
    // do what ever with tag 
    performSegue(withIdentifier: "identifier", sender: self) 
} 
+0

你真的應該避免回答重複的問題 –

+1

好了,會不會在下一次。 –

+0

非常感謝! – fphelp