Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIAlertView仅显示一次_Ios_Swift_Xcode_Uialertcontroller - Fatal编程技术网

Ios UIAlertView仅显示一次

Ios UIAlertView仅显示一次,ios,swift,xcode,uialertcontroller,Ios,Swift,Xcode,Uialertcontroller,我有一个只需弹出一次的条款协议,但是每次应用程序启动时它都会弹出,我如何才能使它只弹出一次,当按下时,我同意不再弹出,除非应用程序被删除并重新下载。我正在努力跟上 我的agree函数是一个警报控制器我忘记在agree()之后添加 如果同意或不同意,只需在UserDefaults中保存一个bool和答案,并检查键“演练”是否存在。如果没有,您将向他显示警报,如果发现,则什么也不做 将其添加到viewdideappear方法中的初始viewController: let alert = UI

我有一个只需弹出一次的条款协议,但是每次应用程序启动时它都会弹出,我如何才能使它只弹出一次,当按下时,我同意不再弹出,除非应用程序被删除并重新下载。我正在努力跟上


我的agree函数是一个警报控制器

我忘记在agree()之后添加


如果同意或不同意,只需在UserDefaults中保存一个bool和答案,并检查键“演练”是否存在。如果没有,您将向他显示警报,如果发现,则什么也不做

将其添加到
viewdideappear
方法中的初始viewController:

    let alert = UIAlertController(title: "Message", message: "You need to agree to terms and conditions", preferredStyle: .alert)
    let action = UIAlertAction(title: "Not Agreed", style: .default) { (action) in

        UserDefaults.standard.set(false, forKey: "WalkThrough")

        alert.dismiss(animated: true, completion: nil)
    }
    let action2 = UIAlertAction(title: "Agreed", style: .default) { (action) in

        UserDefaults.standard.set(true, forKey: "WalkThrough")

        alert.dismiss(animated: true, completion: nil)
    }

    alert.addAction(action)
    alert.addAction(action2)


    if (UserDefaults.standard.object(forKey: "WalkThrough") == nil) {
        //show alert and save answer
        self.present(alert, animated: true, completion: nil)

    }

请使用问题的编辑链接添加其他信息。回答后按钮只能用于完整回答问题。-编辑什么?完整的答案是,我忘记添加行以将其设置为true,这就是答案
UserDefaults.standard.set(true, forKey: "Walkthrough")
    let alert = UIAlertController(title: "Message", message: "You need to agree to terms and conditions", preferredStyle: .alert)
    let action = UIAlertAction(title: "Not Agreed", style: .default) { (action) in

        UserDefaults.standard.set(false, forKey: "WalkThrough")

        alert.dismiss(animated: true, completion: nil)
    }
    let action2 = UIAlertAction(title: "Agreed", style: .default) { (action) in

        UserDefaults.standard.set(true, forKey: "WalkThrough")

        alert.dismiss(animated: true, completion: nil)
    }

    alert.addAction(action)
    alert.addAction(action2)


    if (UserDefaults.standard.object(forKey: "WalkThrough") == nil) {
        //show alert and save answer
        self.present(alert, animated: true, completion: nil)

    }