TableViewController.swiftのコード
swift
1import UIKit 2 3class TableViewController: UITableViewController { 4 var name = "テスト" 5 override func prepare(for segue: UIStoryboardSegue, sender: Any!) { 6 if segue.identifier == "segue" { 7 let TweetContentsView = (segue.destination as? ViewController)! 8 TweetContentsView.foo = name 9 } 10 } 11 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 12 return 1 13 } 14 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 15 let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! TableViewCell 16 return cell 17 } 18}
TableViewCell.swiftのコード
swift
1class TableViewCell: UITableViewCell { 2 3 @IBAction func action(_ sender: Any) { 4 UIApplication.shared.keyWindow?.rootViewController?.performSegue(withIdentifier: "segue", sender: TableViewController()) 5 } 6 7 override func awakeFromNib() { 8 super.awakeFromNib() 9 } 10 11 override func setSelected(_ selected: Bool, animated: Bool) { 12 super.setSelected(selected, animated: animated) 13 } 14 15}
ViewController.swiftのコード
swift
1class ViewController: UIViewController { 2 var foo = String() 3 4 @IBOutlet weak var label: UILabel! 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 8 label.text = foo 9 // Do any additional setup after loading the view. 10 } 11}
これを実行し、カスタムセル上のボタンをタップするとこのエラーが出てしまいます
2017-10-29 16:24:35.232819+0900 ta[8447:129852] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x7facc6032200>) has no segue with identifier 'segue''
*** First throw call stack:
(
0 CoreFoundation 0x00000001067df1cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102e99f41 objc_exception_throw + 48
2 UIKit 0x0000000103609c30 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
3 ta 0x0000000102581569 _T02ta13TableViewCellC6actionyypF + 361
4 ta 0x0000000102581718 _T02ta13TableViewCellC6actionyypFTo + 72
5 UIKit 0x000000010346a9bd -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x00000001035e1183 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001035e14a0 -[UIControl _sendActionsForEvents:withEvent:] + 450
8 UIKit 0x00000001035e03cd -[UIControl touchesEnded:withEvent:] + 618
9 UIKit 0x0000000103a47a88 _UIGestureEnvironmentSortAndSendDelayedTouches + 5560
10 UIKit 0x0000000103a4193e _UIGestureEnvironmentUpdate + 1483
11 UIKit 0x0000000103a41327 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
12 UIKit 0x0000000103a403d3 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 288
13 UIKit 0x00000001034e045c -[UIWindow sendEvent:] + 4102
14 UIKit 0x0000000103485802 -[UIApplication sendEvent:] + 352
15 UIKit 0x0000000103db7a50 __dispatchPreprocessedEventFromEventQueue + 2809
16 UIKit 0x0000000103dba5b7 __handleEventQueueInternal + 5957
17 CoreFoundation 0x00000001067822b1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
18 CoreFoundation 0x0000000106821d31 __CFRunLoopDoSource0 + 81
19 CoreFoundation 0x0000000106766c6b __CFRunLoopDoSources0 + 267
20 CoreFoundation 0x00000001067661ff __CFRunLoopRun + 1279
21 CoreFoundation 0x0000000106765a89 CFRunLoopRunSpecific + 409
22 GraphicsServices 0x0000000108f359c6 GSEventRunModal + 62
23 UIKit 0x0000000103468d30 UIApplicationMain + 159
24 ta 0x0000000102582a87 main + 55
25 libdyld.dylib 0x0000000107908d81 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
どのようにすればカスタムセル上のボタンをタップで値をViewControllerに受け渡して画面遷移できるのでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/29 12:02