1

UISearchBarsearchButton をクリックすると読み込まれる があります。したがって、メソッドfunc searchBarSearchButtonClicked(searchBar: UISearchBar)func searchBarCancelButtonClicked(searchBar: UISearchBar)デリゲート メソッドがあります。ただし、問題は、a が埋め込まれた別のビュー コントローラーUINavigationControllerに移動し、検索バーのあるページに戻って検索ボタンをクリックすると、タイトル ビュー全体が表示されないことです。現在、私のコードは次のとおりです。

func searchbarPopulate() {
        tempSearchBar = searchButton
        searchBar2.delegate = self
        searchBar2.searchBarStyle = UISearchBarStyle.Minimal
        searchBar2.showsCancelButton = true
    }

    @IBAction func tapSearchButon(sender: AnyObject) {
        self.viewDidLoad()
        searchbarPopulate()
        self.navigationItem.rightBarButtonItem = nil
        navigationItem.titleView = searchBar2
        searchBar2.alpha = 0
        navigationItem.setLeftBarButtonItem(nil, animated: true)
        UIView.animateWithDuration(0.5, animations: {
//            self.searchBar2.alpha = 1
            }, completion: { finished in
                self.searchBar2 .becomeFirstResponder()
                self.searchBar2.alpha = 1
            })
    }

    func searchBarSearchButtonClicked(searchBar: UISearchBar) {
        attractionsMap.removeAnnotations(attractionsMap.annotations);
        performYelpSearch(searchBar.text)
        searchBarCancelButtonClicked(searchBar)
    }
    func searchBarCancelButtonClicked(searchBar: UISearchBar) {
        UIView.animateWithDuration(0.5, animations: { () -> Void in
            searchBar.alpha = 0
            }) { (completed) -> Void in
//                self.navigationItem.titleView = "Attractions"
                // Make Title View of Attractions in Sketch
                self.navigationItem.rightBarButtonItem = self.searchButton

        }
}

これは、ピンの注釈がタップされ、アトラクションの詳細 VC にセグエされたときです。

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
    if (control == view.rightCalloutAccessoryView) {
        let selectedLocation = view.annotation;
        let selectedCoordinate = view.annotation.coordinate;
        var latitude = selectedCoordinate.latitude
        var longitude = selectedCoordinate.longitude
        var location:CLLocation = CLLocation(latitude: latitude, longitude: longitude)
        let businessPlacemark = MKPlacemark(coordinate: selectedCoordinate, addressDictionary: nil)
        indicatedMapItem = selectedCoordinate;
        let resturantMock:Resturant = Resturant(dictionary: resultQueryDictionary)
        let dataArray = resultQueryDictionary["businesses"] as! NSArray
        var foundDisplayAddress:String = "Address not found"
        for business in dataArray {
            let obj = business as! NSDictionary
            var yelpBusinessMock: YelpBusiness = YelpBusiness(dictionary: obj)
            if yelpBusinessMock.latitude == view.annotation.coordinate.latitude {
                if yelpBusinessMock.longitude == view.annotation.coordinate.longitude {
                    attractionDict = obj;
                    foundDisplayAddress = yelpBusinessMock.displayAddress
                    businessMock = Business(dictionary: obj)
                }
            }
        }
        attractionLocationString = foundDisplayAddress
        performSegueWithIdentifier("attractionToDetail", sender: view);
    }
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "attractionToDetail" {
        if let annotation = (sender as? MKAnnotationView)?.annotation {
            if let ivc = segue.destinationViewController as? AttractionsDetailViewController {
                searchBarCancelButtonClicked(searchBar2)
                ivc.attractionLocation = self.indicatedMapItem
                ivc.attractionDetailAddressString = self.attractionLocationString
                ivc.currentBusiness = self.attractionDict
                ivc.businessToUse = self.businessMock
            }
        }
    }

わかりやすくするために、何が起こるかを示す gif を次に示します。
ここに画像の説明を入力

4

1 に答える 1

1

navigationItem.titleViewを正しく設定していることを確認してください。titleViewを nil に設定しています

于 2015-09-12T14:43:26.590 に答える