ios - 将 View Controller 关闭到上一个 View Controller

标签 ios swift swift-protocols

我知道很多人可能会问这个问题。我也找到了解决方案,但我无法理解我的代码中有什么问题?

popcontroller.swift:

protocol DataSendDelegate {
    func sendgetattid(pop_att_id: Int, pop_in_time: String)
}
var delegate: DataSendDelegate? = nil

if statuss == "200" {
let send_pop_att_id = att_id
let send_pop_in_time = in_time
self.navigationController?.popViewController(animated: true)
self.dismiss(animated: true) {                                    
self.delegate?.sendgetattid(pop_att_id: send_pop_att_id, pop_in_time: send_pop_in_time)
}
}

在上面的代码中,我得到了正确的值,但它并没有关闭并转到下一个 View Controller 。

attendanceViewController.swift:

class attendanceViewController: UIViewController , DataSendDelegate {
func sendgetattid(pop_att_id: Int, pop_in_time: String) {
        DispatchQueue.main.async {
            self.inTimeTextField.text = pop_in_time
            self.get_att_id = pop_att_id
            self.in_time_button.isEnabled = false
            self.out_time_button.isEnabled = true
        }
    }

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let popVC = segue.destination as? PopUpViewController
        {
            popVC.popEmailID = att_emp_id
            popVC.delegate = self
        }
    }
}

最佳答案

根据您的评论更新: 你没有呈现 viewController。你已经推送了一些 View Controller 。所以就弹出它。丢弃 dismiss

self.delegate?.sendgetattid(pop_att_id: send_pop_att_id, pop_in_time: send_pop_in_time)
self.navigationController?.popViewController(animated: true)

关于ios - 将 View Controller 关闭到上一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50040861/

相关文章:

ios - CoreML - 如何将 InceptionV3 的图像预处理为 MultiArray <Double, 3>?

ios - 调用出队单元格时出队可重用单元格崩溃

swift - 强制 UIButton 只有一个标题行

ios - 为什么 swift 隐藏受限协议(protocol)的默认实现?

arrays - 如何泛化一个参数是具有不同属性的不同结构的函数?

ios - 为什么较大的图像不会出现在共享扩展或操作扩展中?

ios - 无法使用 Bundle main url 从文件中找到 URL

ios - 将 XCFramework 嵌入到具有项目框架依赖项的应用程序中

Swift map 语义

ios - 如何在我的协议(protocol)中正确使用 associatedType