2016-08-26 12 views
1

私はUISearchControllerを実装する作業テーブルビューを持っています。今、私はinstagram、twitterのような検索アクションの開始前後に2つの異なるテーブルビューを表示したいと思います。最近の検索結果を一覧表示する別のテーブルビューを表示したい。swift:検索前/後に別のテーブルビューを表示するUISearchcontroller

マイストーリーボードのセットアップは次のとおりです。

- >タブバー - >ナビゲーションバー - > SearchResultsTableViewController - >ナビゲーションバー - > recentSearchesTableView

私はsearchResultsTableViewで検索バーを持っています。

class SearchResultsTableViewController: UITableViewController, SearchTableViewControllerDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad()   
     if ((self.searchResults?.count) == 0) { 
      performSegueWithIdentifier("ShowSearchView", sender: self) 
     } 
    } 

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if segue.identifier == "ShowSearchView" { 
      if let destinationNavigation = segue.destinationViewController as? UINavigationController { 
       if destinationNavigation.viewControllers.count > 0 { 
        if let searchVC = destinationNavigation.viewControllers[0] as? SearchTableViewController { 
         searchVC.delegate = self 
        } 
       } 
      } 
     } 
    } 

セグを使用せずにこれを実現する方法はありますか?

答えて

1

ユーザーが検索バーに入力した内容に応じてメインのテーブルビューの内容を変更することはできますが、別のビューには送信しませんが、検索者が2人ではなく2つのテーブルを表示するかどうかはわかりません空であれば、テーブルビューは最新の検索結果を表示できます。テーブルに検索バーのコンテンツに関連するコンテンツが表示されている場合は、より具体的に表示できますか?

+0

を使用していた知っているので、セクションの分周器は、しかし、あなたが望む見えるようにすることができますが... ありがとうございました –

1

私は@Luis Perezに同意します.2つのテーブルビューを使用しないでください。

私は

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 2 
    } 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    if indexPath.section == 0 { 
     return recentSearches.count 
    } else { 
     if searchController.active && searchController.searchBar.text! != "" { 
      return searchResults.count 
     } 
     return 0 
    } 
} 

注どうなるのかHERESに

:あなたは私はあなたがあなたのアドバイスを試みたが、私が望んでいたとして、それが働く2 tableviews

関連する問題