首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UITableViewController didSelectRowAt未正确解除

UITableViewController didSelectRowAt未正确解除
EN

Stack Overflow用户
提问于 2019-05-24 08:11:00
回答 1查看 138关注 0票数 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甚至还没有正确地忽略它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-24 08:14:07

当您解除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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56284334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档