Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 返回到主(根)视图控制器的顺序不';行不通_Ios_Swift_Segue_Uistoryboardsegue_Poptoviewcontroller - Fatal编程技术网

Ios 返回到主(根)视图控制器的顺序不';行不通

Ios 返回到主(根)视图控制器的顺序不';行不通,ios,swift,segue,uistoryboardsegue,poptoviewcontroller,Ios,Swift,Segue,Uistoryboardsegue,Poptoviewcontroller,我有导航控制器和两个视图控制器:MainVC(root)和SearchVC 以下是层次结构: 首先,我正在使用这个从MainVC(“+”导航项)到SearchVC的转换函数: @objc func goToSearchVC() { let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let searchVC = storyBoard.instantiateViewCont

我有
导航控制器
和两个视图控制器:
MainVC
(root)和
SearchVC

以下是层次结构:

首先,我正在使用这个从
MainVC
(“+”导航项)到
SearchVC
的转换函数:

@objc func goToSearchVC() {

        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let searchVC = storyBoard.instantiateViewController(withIdentifier: "SearchVC") as! SearchVC

        //Hide system navigation controller back button and add custom close button
        DispatchQueue.main.async {
            searchVC.navigationItem.hidesBackButton = true
            searchVC.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "closeBtn_20"), style: .plain, target: self, action: #selector(self.closeBtnTapped))
            searchVC.navigationItem.title = ""
        }

        //It's constructed function for custom transition type, in this case transition from top, it's works well
        animatedTransition(navi: self.navigationController!,transitionType: kCATransitionFromTop, duration: 0.5)

        //push to SearchVC
        self.navigationController?.pushViewController(searchVC, animated: false)

    }

    //close button function for SearchVC navibar
    @objc public func closeBtnTapped() {
         animatedTransition(navi: self.navigationController!, transitionType: kCATransitionFromBottom, duration: 0.5)
        navigationController?.popViewController(animated: false)

        let mainNaviBar = self.navigationController!.navigationBar
        mainNaviBar.isHidden = true
    }
此“+”按钮切换和关闭按钮“x”弹出切换效果良好:

SearchVC
中,我使用
GMSAutocompleteResultsViewController
搜索位置,并尝试使用
goToVc()
函数弹出到
MainVC
我依次检查了所有3个“弹出”选项的性能,但它们都不起作用):

upd
self.view.window!。rootViewController?.disclose(动画:false,完成:nil)
也不起作用

class SearchVC: UIViewController, CLLocationManagerDelegate {

            var resultsViewController: GMSAutocompleteResultsViewController?
            var searchController: UISearchController?
            var resultView: UITextView?

            override func viewDidLoad() {
                super.viewDidLoad()


                //Make navigation bar visible
                let mainNaviBar = self.navigationController?.navigationBar
                mainNaviBar?.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

                // 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

            }//viewDidLoad()

            //function for segue to existing VC, MainVC
            func goToVc() {

    //It's constructed function for custom transition type, in this case transition from top, it's works well
animatedTransition(navi:self.navigationController!,transitionType: kCATransitionFromTop, duration: 0.5)   

       //!!!I checked the performance of all these "pop" options in turn, but they do not work

              //Option 1, popToRootViewController (MainVC) - Doesn't work
    self.navigationController?.popToRootViewController(animated: false)

     //Option 2, popViewController(animated: false) - Doesn't work
    self.navigationController?.popViewController(animated: false)

     //Option 3, popToViewController - Doesn't work
    self.navigationController?.popToViewController(MainVC(), animated: false)
            }

        }//class

    Extension:

        // Handle the user's selection.
        extension SearchVC: GMSAutocompleteResultsViewControllerDelegate {
            func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                                   didAutocompleteWith place: GMSPlace) {
                searchController?.isActive = false
                // Do something with the selected place.
                print("Place name: \(place.name)")
                print("Place address: \(place.formattedAddress)")
                print("Place attributions: \(place.attributions)")
                print("Place coordinats:\(place.coordinate)")


                //segue to MainVC
                goToVc()

            }
            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
            }
        }
在所有三种“pop to MainVC”情况下,未发生到
MainVC
的转换,并弹出到当前VC:

upd
self.view.window!。rootViewController?.disclose(动画:false,完成:nil)
具有相同的效果

如何修复此问题,并将其转换到
MainVC