【问题标题】:UITableViewController didSelectRowAt not properly dismissingUITableViewController didSelectRowAt 没有正确解散
【发布时间】:2019-10-10 13:35:11
【问题描述】:

正如您在下面的代码中看到的那样,一旦选择了一行,我已经尝试了一些方法来将 UIViewTableController 解散回我的父 ViewController 中

我的 UITableViewController 中的didselectRowAt 代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    //self.storyboard?.instantiateInitialViewController()
    //self.navigationController?.popViewController(animated: true)
    print("before dismissing")
    self.dismiss(animated: true, completion: {
        print("dismissing")
        self.delegate?.showWeatherInfo()
    })
    print("after dismissing")


    let geoCoder = CLGeocoder()
    geoCoder.geocodeAddressString(self.searchResults[indexPath.row], completionHandler: {(placemarks: [CLPlacemark]?, error: Error?) -> Void in
        if let placemark = placemarks?[0] {


            print(placemark)


        }
    })

    /*
    self.dismiss(animated: true, completion: {
        self.delegate?.showWeatherInfo()
    })
     */
}

同一类的协议:

protocol ShowWeather{
    func showWeatherInfo()
}

我在 ViewController 中调用它的地方:

@IBAction func searchButton(_ sender: UIButton) {
    searchButtonUIChanges()
    textFieldBg_view.backgroundColor = UIColor.clear

    //create searchresult object and add it as a subview
    searchResultController = SearchResultsController()
    searchResultController.delegate = self
    addChild(searchResultController)
    searchResultController.view.backgroundColor = UIColor.clear
    searchResultController.view.frame = CGRect(x: 0, y: 64+textFieldBg_view.frame.size.height - 25, width: self.view.frame.size.width, height: self.view.frame.size.height - 50)
    view.addSubview(searchResultController.view)
    searchResultController.didMove(toParent: self)



    let screenHeight = -(UIScreen.main.bounds.height/2 + textFieldBg_view.frame.height/2)
    textFieldBg_view.transform = CGAffineTransform(translationX: 0, y: screenHeight)

    UIView.animate(withDuration: animateDuration, delay: delay, usingSpringWithDamping: springWithDamping, initialSpringVelocity: 0, options: .allowUserInteraction, animations: {
        self.textFieldBg_view.transform = .identity
    }, completion: nil)

    searchTextField.becomeFirstResponder()
}

很明显,在解除打印工作之前和之后,但在完成内的解除工作却没有。我目前还没有将任何信息传递回 UIViewController 的原因是,我什至还没有到达那里。

是的,在我的 ViewController 类标头中,我有 TableViewController 类协议,但这无关紧要,因为 UITableViewController 甚至还没有正确关闭。

【问题讨论】:

    标签: swift uitableview appdelegate dismissviewcontroller


    【解决方案1】:

    当您关闭 vc 时,它会被定义,因此您需要在关闭之前传递数据

    print("before dismissing \(delegate)")  // print delegate to see if nil
    self.delegate?.showWeatherInfo()
    self.dismiss(animated: true, completion: {
        print("dismissing")
    })
    

    此外,如果将 vc 推入导航 dismiss 将不起作用,您需要使用

    self.navigationController?.popViewController(animated: true)
    

    【讨论】:

    • 他的完成块中的解雇打印没有调用,所以这不是答案。 “......完成内的解雇没有。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    相关资源
    最近更新 更多