![](/img/trans.png)
[英]How to Segue from Custom TableViewCell to Another ViewController (Swift)
[英]Not able to jump from tableViewCell to another viewController using segue
嗨,我是swift和Xcode 6的新手,所以我嘗試執行segue從單元格跳轉到另一個viewController,如下所示:-
我也嘗試以編程方式使用以下代碼:-
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("selected row \(indexPath.row)")
self.performSegueWithIdentifier("segueCust", sender: self)
}
仍然無法執行,如果在上述代碼上運行,則應用崩潰,並顯示以下錯誤:-
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<swiftDemo.DetailTableViewController: 0x7fdab1606ee0>) has no segue with identifier 'segueCust''
不知道為什么會出現此錯誤,因為在情節提要中我已為segue分配了此標識符。
而且,永遠不會調用以下segue方法。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)
另外,我添加了一個按鈕,並使用情節提要從一個viewController到另一個viewController執行segue,然后工作正常。 到目前為止,我可能會丟失或犯一個愚蠢的錯誤。 任何幫助,將不勝感激。 提前致謝。
如果要使用self.performSegueWithIdentifier
以編程方式調用segue,則需要從視圖控制器本身進行鏈接。 (這就是代碼中的self
。)從您的圖像看來,您似乎已將其連接到單元而不是視圖控制器。
(為什么單元連接不能自動工作,我不知道。)
我將其修復如下:
//Embedded my tableVC with navigationController and provided that navigationController a storyboard id.
//Used that navigationController and presented it on my current VC as below.
var storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var vc : UINavigationController = storyboard.instantiateViewControllerWithIdentifier("naviVC") as UINavigationController
self.presentViewController(vc, animated: true, completion: nil)
還將我的tableView單元格與另一個VC(如下所示)連接,其余部分應按預期順利進行。 在下面,我為導航控制器提供了情節提要ID。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.