UITableViewController didSelectRowAt правильно не увольняя - PullRequest
0 голосов
/ 24 мая 2019

Как вы можете видеть ниже в моем коде, я попытался несколько вещей, чтобы выбросить UIViewTableController обратно в мой родительский ViewController, как только строка выбрана, но не повезло

didselectRowAt код в моем UITableViewController:

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 все еще даже не удаляется должным образом.

1 Ответ

0 голосов
/ 24 мая 2019

Когда вы закрываете виртуальный канал, он деинициализирован, поэтому вам нужно передать данные перед удалением

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

Также, если виртуальный канал проталкивается внутри навигации dismiss не будет работать, и вам нужно использовать

self.navigationController?.popViewController(animated: true)
...