IOS navigationController?.popToRootViewController有错

标签 ios swift uiviewcontroller navigationcontroller poptoviewcontroller

@IBAction func addInformation(_ sender: UIBarButtonItem) {
    // check rateHourly has value
    if let editedRateHourly = rateHourly.text {
        print("editedRateHourly condition is \(editedRateHourly)")
        if editedRateHourly != ""{
            print("not nil")
            // check edit value is number?
            let num = Int(editedRateHourly)
            if num != nil {
                print("is num")
                // add to database
                UserDefaults.standard.set(editedRateHourly, forKey: "\(findDate())")
                UserDefaults.standard.synchronize()
                // back to last viewController
                navigationController?.popToRootViewController(animated: true)
            }else{
                print("not num")
                print("error alert push!!")
                popErrorAlert()
            }
        }else {
            print("nil")
            print("editedRateHourly condition is nil")
            popErrorAlert()
        }
    }
}
@IBAction func cannelInformationPage(_ sender: UIBarButtonItem) {
    navigationController?.popToRootViewController(animated: true)
}

我想创建一个新的简单编辑页面。这对我来说是两个问题,当我完成版本时,if-else 将检查条件是否正确,然后保存数据 popToRootViewControlle。当我完成编辑时,我单击“addInformation”BarButtonItem,但我的 UI 出错了。另一个错误是当我点击 editField 但我没有输入任何条件时。然后我点击“cannelInformationPage”UIBarButtonItem。它也会出错。

It's what I get wrong

wrong information

最佳答案

因为它返回 Bool

_ = navigationController?.popToRootViewController(animated: true)

关于IOS navigationController?.popToRootViewController有错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43314743/

相关文章:

iphone - 如何实现 UIViewController 旋转以响应方向变化?

ios - 我在 Swinject 中做错了什么?

ios - 如果应用程序第一次启动,需要一个简单的动画吗?

ios - 在启动时呈现 UIViewController,以在 UISplitViewController 中显示动画启动屏幕

ios - 通过两个不同的带部分的 NSFetchedResultsControllers 的单 TableView

ios - 如何从一致的类中正确设置协议(protocol)中的属性?

ios - 如何 'cancel' 查看自定义容器 Controller 转换的外观转换

ios - 用特定类型覆盖 UIViewController.view

iOS:如何使用 FQL 从 Facebook 获取事件(开始时间 > 今天)?

ios - 如何防止自定义标题在部分更新时闪烁?