0

以下のコードでわかるように、行が選択されて運が悪くなったら、 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 がまだ適切に破棄されていないため、これは関係ありません。

4

1 に答える 1