J'ai un UITableVIewController qui implémente UISearchBarDelegate, la vue est intégrée dans un contrôleur de navigation.Boîte de recherche UISearchController Shift Down on Tap
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
}
Je trouve que lorsque j'ai désactivé la translucidité de la barre de navigation Boîte de recherche déplace sa position vers le bas.
Si je mets le definesPresentationContext = false
alors la barre de recherche ne se déplace pas vers le bas, si j'entrer du texte dans la zone de recherche et sélectionnez l'un des résultats de la fenêtre modale résultant ne peut pas ouvrir. Je reçois l'erreur suivante:
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)
Ci-dessous mon code Segue:
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
}
}
Je suis perdu à ce qu'il faut faire. Je veux quitter la barre de navigation avec la translucidité désactivée et je dois être en mesure de lancer une fenêtre modale à partir des résultats de la recherche. Des pensées sur la façon d'accomplir cela?
duplication possible de [Comportement de décalage de vue UISearchDisplayController étrange dans iOS 7 lorsqu'il est intégré dans la barre de navigation] (http://stackoverflow.com/questions/20731360/strange-uisearchdisplaycontroller-view-offset-behavior-in-ios-7- quand-inclus-dans) –