IOS navigationController?.popToRootViewController有错误

时间:2017-04-10 03:58:34

标签: 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

2 个答案:

答案 0 :(得分:1)

因为它返回Bool

let comboValue : any;

<select [(ngModel)]="comboValue">
 <option *ngFor = "let combo of combos" value={{combo}}>{{combo}}
 </option>
</select>

答案 1 :(得分:1)

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

如果你想回到最后一个视图控制器而不是你可以尝试上线,希望它能为你工作。