12

UISearchBarDelegate を実装する UITableVIewController があり、ビューは Navigation Controller 内に埋め込まれています。

    class FacilityTableViewController: UITableViewController, UISearchResultsUpdating, UISearchBarDelegate, AmenityFilterDelegate {

        // MARK: - Public Variables

        var targetFacilities = [Int]()
        var searchController: UISearchController = UISearchController(searchResultsController: nil)

        // MARK: - Private Variables

        private var viewModel: FacilityTableViewModel!
        private let parkGreenColor = UIColor(red: 73/255, green: 136/255, blue: 84/255, alpha: 1)
        private var showEmptyMessage = false

        // MARK: - View Lifecycle

        /**
        Setup view after loading
        */
        override func viewDidLoad() {
            super.viewDidLoad()

            trackScreenView("Facility Table View")

            if targetFacilities.isEmpty {
                viewModel = FacilityTableViewModel()
            } else {
                viewModel = FacilityTableViewModel(facilityIds: targetFacilities)
            }

            // Seup search controller
            searchController.searchResultsUpdater = self
            searchController.dimsBackgroundDuringPresentation = false
            searchController.hidesNavigationBarDuringPresentation = false
            searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, searchController.searchBar.frame.origin.y, searchController.searchBar.frame.size.width, 44)
            searchController.searchBar.tintColor = UIColor.whiteColor()
            searchController.searchBar.barTintColor = parkGreenColor
            searchController.searchBar.translucent = false

            self.definesPresentationContext = true

            tableView.tableHeaderView = searchController.searchBar
        }

検索をタップする前に

ナビゲーション バーの Translucent プロパティを無効にすると、検索ボックスの位置が下に移動することがわかりました。

検索をタップした後

を設定したdefinesPresentationContext = false場合、検索バーは下に移動しませんが、検索ボックスにテキストを入力して結果の 1 つを選択すると、結果のモーダル ウィンドウを開くことができません。次のエラーが表示されます。

の検索結果

    2015-03-17 15:06:56.101 VB ParkFinder[16368:2667719] Warning: Attempt to present <UINavigationController: 0x7fa2f9ced930>  on <VB_ParkFinder.FacilityTableViewController: 0x7fa2f9c27ba0> which is already presenting (null)

以下は私のセグエコードです:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        let navController = segue.destinationViewController as UINavigationController
        if segue.identifier == "facilityDetailsSegue" {
            let detailsViewController = navController.childViewControllers.last as FacilityDetailsViewController

            if let indexPath = tableView.indexPathForSelectedRow() {
                var facilityId: Int
                if searchController.active {
                    facilityId = viewModel.idForSearchResultsAtIndexPath(indexPath)
                } else {
                    facilityId = viewModel.idForFacilityAtIndexPath(indexPath)
                }

                detailsViewController.currentFacilityId = facilityId
            }
        } else if segue.identifier == "FilterPopover" {
            let aftvc = navController.childViewControllers.last as AmenityFilterTableViewController
            aftvc.delegate = self
        }
    }

私は何をすべきか迷っています。半透明性をオフにしてナビゲーション バーを残したいのですが、検索結果からモーダル ウィンドウを起動できるようにする必要があります。これを達成する方法について何か考えはありますか?

4

1 に答える 1

6

私は同じ問題を抱えていました、見てください

ナビゲーション バーに埋め込まれた場合の iOS 7 での奇妙な UISearchDisplayController ビュー オフセット動作

これで私の問題は解決しました。

重複としてマークされる可能性があると思いますが、その方法がわかりません。

于 2015-03-26T03:12:07.847 に答える