我在通过 show segue 连接到新的视图控制器时遇到了一些问题。我已经能够使用当前的 segue,但想使用推送/显示导航堆栈。我收到此错误...“正在发生现有转换或演示;导航堆栈将不会更新。” 提前感谢您的帮助!
// 从 homecontroller 转到 searchVC
func handleSearch() {
let vc = SearchVC()
show(vc, sender: self)
}
// 在 searchVC 类中设置搜索栏
func loadPlacesSearchBar() {
searchController?.searchBar.isHidden = false
resultsViewController = GMSAutocompleteResultsViewController()
resultsViewController?.delegate = self
searchController = UISearchController(searchResultsController: resultsViewController)
searchController?.searchResultsUpdater = resultsViewController
// Put the search bar in the navigation bar.
searchController?.searchBar.sizeToFit()
navigationItem.titleView = searchController?.searchBar
searchController?.searchBar.placeholder = "search places"
// When UISearchController presents the results view, present it in
// this view controller, not one further up the chain.
definesPresentationContext = true
// Prevent the navigation bar from being hidden when searching.
searchController?.hidesNavigationBarDuringPresentation = false
}
// SearchVC 的扩展
extension SearchVC: GMSAutocompleteResultsViewControllerDelegate {
func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
didAutocompleteWith place: GMSPlace) {
searchController?.isActive = false
// Do something with the selected place.
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self as? GMSAutocompleteViewControllerDelegate
print("Place name: \(place.name)")
print("Place address: \(String(describing: place.formattedAddress))")
print("Place attributions: \(String(describing: place.attributions))")
self.dismiss(animated: true, completion: nil)
let mapView = MapViewController()
show(mapView, sender: self)
// let mapView = MapViewController()
// let navController = UINavigationController(rootViewController: mapView)
// present(navController, animated: true, completion: nil)
DispatchQueue.main.async {
self.dismiss(animated: true, completion: nil)
}
}
func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
didFailAutocompleteWithError error: Error){
// TODO: handle the error.
print("Error: ", error.localizedDescription)
}
// Turn the network activity indicator on and off again.
func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}
func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
}