2016-10-07 8 views
1

私は最初から別のViewControllerスウィフトSearchResultsControllerセグエ - 「レシーバーは...識別子とはセグエを持っていない 『testSeg』 '」

にsearchResultControllerからsegueing問題が生じています: 私は3つのコントローラ、とAのUIViewControllerを持っています内部に埋め込まれたCollectionViewとUISearchController、searchResultControllerとして機能するUITableViewController、およびクリックされたときに各tableviewセルが分割される最後のUIViewControllerがあります。 Here is an image of Main.StoryboardHere the segue with its identifier is shown, which is the problem

セグエがSearchResultsTableViewController自体からリンクされている、いないtableviewcell 私は、検索結果をクリックすると、私はSearchResultsControllerでdidSelectRowAtIndexPathメソッドからそのセグエを行います。しかし、私は "Receiver ..."という識別子を持つセグを持っていません。 'testSeg' '"というエラーです。明確にするために

、コントローラの名前とその役割は以下のとおりです。

1)DiscoverViewControllerは:(含まUISearchControllerとCollectionView)

2)正しくフィルタリングし、任意のデータを更新searchResultsControllerとしてSearchResultsTableViewController(使徒各セルは、このコントローラからセグエになっている)

3)のUIViewController(セグエの宛先である単純なのUIViewController)

問題はセグーであり、他のすべては意図どおりに実行されます。これはSearchResultsTableViewControllerのコードです。

注:これは私がスウィフト2.3を使用して、これを試みたとにsearchResults配列がDiscoverViewControllerから来

private let reuseIdentifer = "searchCell" 

class SearchResultsTableViewController: UITableViewController { 

var searchResults: [String]! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    self.tableView!.register(UITableViewCell.self, forCellReuseIdentifier: reuseIdentifer) 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 

override func numberOfSections(in tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return (searchResults?.count)! 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifer, for: indexPath) 
    // Configure the cell... 
    cell.textLabel?.text = searchResults[indexPath.item] 
    return cell 
} 

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    self.performSegue(withIdentifier: "testSeg", sender: self) 
} 
} 

同じエラーを得たスウィフト3であるという事実を無視することができます。セグの場合を除いてすべてうまく動作します。行を選択すると、アプリはエラーでクラッシュします。

2016-10-07 12:17:51.216 MultiTestDemo[1028:10002] *** Terminating app 
due to uncaught exception 'NSInvalidArgumentException', reason: 
'Receiver (<MultiTestDemo.SearchResultsTableViewController: 
0x7fea214055f0>) has no segue with identifier 'testSeg'' 

私は、セグ識別子にスペースや何もないことを確認しました。私はそれをSearchResultsTableViewControllerのdidselectrowatindexpath関数に直接コピーしました。

結論として、IBで接続したときに、SearchResultsTableViewControllerがsegue(または任意の識別子のセグ)を識別できなくなった理由についての助けとなります。どんな助けでも大歓迎です。

+0

どのようにSearchResultsTableViewControllerをインスタンス化しますか? – pbasdf

+0

あなたのGitHubリンクでそれを見つけました。この問題は、SearchResultsTableViewControllerをインスタンス化する方法に起因します。この行は: 'let searchResultsController = SearchResultsTableViewController()'はそれを作成しますが、ストーリーボードへの参照は一切ありません。したがって、ストーリーボードに定義されているセグエについては何も知りません。代わりに、UIStoryboardメソッド 'instantiateViewControllerWithIdentifier'(必要に応じてストーリーボード内に識別子を追加したもの)を使用する必要があります。 – pbasdf

+0

これは間違いなく動作します。実際にこれを試してみましたが、searchREsultsControllerで繰り返しインスタンスを削除するまでクラッシュし続けました。答えてくれてありがとう。しかし、「帰り道」は存在しないようです。私はデモにナビゲーションコントローラがないことを認識していますが、ユーザーが検索結果にどのくらい戻ってくるのでしょうか?たとえば、これはユーザーの検索機能でしたか?前回の実装ではうまくいきましたが、戻ってみることはできましたが、searchResultsControllerを使用すると、方法が必要なときに問題が発生します。 –

答えて

1

エラーはかなり明確です。識別子がtestSegのセグはありません。セグをクリックし、右のメニューで属性インスペクタに移動し、識別子testSegを追加します。

+0

あなたはsegueを持っていますが、その識別子を設定する必要があります。 –

+0

私は識別子を設定しました。 2枚目の写真を見てください。私の質問で。それは私のストーリーボードのイメージである質問の冒頭のリンクです。私はsegueと識別子を持っています –

+0

次にxcodeを再起動し、プロジェクトをきれいにして再実行してください。 –

0

私は同じ問題があります。私は、新しいセグエと新しいアンワインドセグエを追加識別子を定義し、私のアプリをテストし、私はそれを解決し、両方の新しいsegues

Receiver <...> has no segue with identifier '...'

に同じエラーを取得します。 私の場合、問題は私が誤って2つのストーリーボード、Main.Storyboard(Base)とMain.Storyboard(英語)で同じクラスの2つのインスタンスを持っていたことでした。ストーリーボードの1つにのみ新しいセグが存在しました。 2つのストーリーボードは必要ありませんので、メインを削除するだけです。ストーリーボード(英語)とそれが問題を解決しています。

+0

いくつかのコードも提供してください...事前に感謝! –

+0

Main.Storyboard(英語)を削除しましたが、コードに変更はありませんでした...ありがとう! –

関連する問題