質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

1回答

1712閲覧

カスタムセル上のActiveLabelのアクション時に値を受け渡して遷移

gtime

総合スコア51

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/10/30 07:22

イメージ説明

ストーリーボードはこのように設置しました

swift

1import UIKit 2class TableViewController: UITableViewController { 3 var name = "テスト" 4 override func prepare(for segue: UIStoryboardSegue, sender: Any!) { 5 if segue.identifier == "segue" { 6 let TweetContentsView = (segue.destination as? ViewController)! 7 TweetContentsView.foo = name 8 } 9 } 10 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 11 return 3 12 } 13 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 14 let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! TableViewCell 15 cell.foo() 16 return cell 17 } 18} 19

TableViewController.swiftのコード

swift

1import UIKit 2import ActiveLabel 3class TableViewCell: UITableViewCell { 4 5 @IBOutlet weak var lab: ActiveLabel! 6 7 func foo() { 8 lab.text = "#test aaa" 9 lab.hashtagColor = .red 10 lab.handleHashtagTap { hashtag in 11 UIApplication.shared.keyWindow?.rootViewController?.performSegue(withIdentifier: "segue", sender: nil) 12 } 13 } 14 15 override func awakeFromNib() { 16 super.awakeFromNib() 17 18 } 19 20 override func setSelected(_ selected: Bool, animated: Bool) { 21 super.setSelected(selected, animated: animated) 22 } 23 24}

TableViewCell.swiftのコード

swift

1 2import UIKit 3 4class ViewController: UIViewController { 5 var foo = String() 6 7 @IBOutlet weak var label: UILabel! 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 11 label.text = foo 12 // Do any additional setup after loading the view. 13 } 14}

ViewController.swiftのコード

TableViewCell.swiftの
lab.handleHashtagTap { hashtag in
UIApplication.shared.keyWindow?.rootViewController?.performSegue(withIdentifier: "segue", sender: nil)
}
}

実行時にエラーが出ます
2017-10-30 16:16:33.522675+0900 ta[49920:592588] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x7f9c07021000>) has no segue with identifier 'segue''
*** First throw call stack:
(
0 CoreFoundation 0x000000010bd861cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000108be3f41 objc_exception_throw + 48
2 UIKit 0x000000010934bc30 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
3 ta 0x000000010728d06c T02ta13TableViewCellC3fooyyFySScfU + 620
4 ActiveLabel 0x000000010759af78 _T011ActiveLabelAAC13didTapHashtag33_42C3D6786121DF647E596543A9DC4279LLySSF + 184
5 ActiveLabel 0x000000010758fd59 _T011ActiveLabelAAC7onTouchSbSo7UITouchCF + 5465
6 ActiveLabel 0x000000010759ab6a _T011ActiveLabelAAC12touchesEndedys3SetVySo7UITouchCG_So7UIEventCSg4withtF + 186
7 ActiveLabel 0x000000010759acb8 _T011ActiveLabelAAC12touchesEndedys3SetVySo7UITouchCG_So7UIEventCSg4withtFTo + 104
8 UIKit 0x0000000109789a88 _UIGestureEnvironmentSortAndSendDelayedTouches + 5560
9 UIKit 0x000000010978393e _UIGestureEnvironmentUpdate + 1483
10 UIKit 0x0000000109783327 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
11 UIKit 0x00000001097823d3 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 288
12 UIKit 0x000000010922245c -[UIWindow sendEvent:] + 4102
13 UIKit 0x00000001091c7802 -[UIApplication sendEvent:] + 352
14 UIKit 0x0000000109af9a50 __dispatchPreprocessedEventFromEventQueue + 2809
15 UIKit 0x0000000109afc5b7 __handleEventQueueInternal + 5957
16 CoreFoundation 0x000000010bd292b1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
17 CoreFoundation 0x000000010bdc8d31 __CFRunLoopDoSource0 + 81
18 CoreFoundation 0x000000010bd0dc6b __CFRunLoopDoSources0 + 267
19 CoreFoundation 0x000000010bd0d1ff __CFRunLoopRun + 1279
20 CoreFoundation 0x000000010bd0ca89 CFRunLoopRunSpecific + 409
21 GraphicsServices 0x000000011027e9c6 GSEventRunModal + 62
22 UIKit 0x00000001091aad30 UIApplicationMain + 159
23 ta 0x000000010728e6d7 main + 55
24 libdyld.dylib 0x000000010db55d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
どのようにすればカスタムセル上のActiveLabelのアクション時にViewControllerに値を受け渡して画面遷移できるのでしょうか

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

swift

1 UIApplication.shared.keyWindow?.rootViewController?.performSegue(withIdentifier: "segue", sender: nil)

rootViewControllerはNavigationControllerなのでは?
TableViewControllerから出ている"segue"を呼び出さないとダメですよね?

投稿2017/10/30 08:09

fuzzball

総合スコア16731

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

gtime

2017/10/30 16:16

はい。 TableViewControllerから出ている"segue"を呼び出したいです。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問