簡體   English   中英

可以使用xib手勢識別器進行segue嗎?

[英]possible to segue with xib gesture recognizer?

如果用戶從 xib(通過手勢識別器)而不是 tableView 中的行的其余部分(因為這是一個不同的 segue)點擊像 imageview 這樣的元素,我會嘗試轉到不同的 segue。 我見過有人用目標 C 做這件事,但我不知道如何在 Swift 中做到這一點,有沒有人成功地做到過? 我知道我必須對自定義 xib 文件進行代碼更改,然后讓實際控制​​器進行轉換(如果我要按照目標 C 方式進行)。

因此,如果您的單元格中有 UIButton,則可以使用以下代碼在單擊時執行轉場。

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell : YourCell = tableView.dequeueReusableCell(withIdentifier: "YourCellIdentifier", for: indexPath) as! YourCell
    cell.imageButton.addTarget(self, action: #selector(imageTapped(sender:)), for: .touchUpInside)
    return cell
}


@objc func imageTapped(sender : UIButton) {
    self.performSegue(withIdentifier: "YourIdentifer", sender: self)
}

因此,在 cellForRowAt 中,我們為您的 imageButton 分配了一個函數,該函數將在單擊按鈕時調用,即 imageTapped()

由於您的 imageTapped 函數在您的 viewController 中,您可以通過從 VC1 到 VC2 創建一個來輕松執行轉場

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM