我有一个Xcode
项目,它是一个调查表,里面有几个问题,还有一些按钮,这些按钮可以使用segue标记将一个视图中选择的数据传递给另一个视图。
在调查问卷的末尾,我有一个显示数据按钮,该按钮会将管理员带到显示整个数据的页面,我的问题是任何人都可以触发显示数据事件,我想知道我该怎么去关于添加密码,以便只有管理员才能看到数据的信息。
我看了网上,却没有发现与我需要做的事情有关的事情,大多数网上事情都超过了创建注册页面的目的。
@IBAction func DataReveal(_ sender: UIButton)
{
ID = ID2.text
date = date2.text
Answer1 = answ1.text
Answer2 = answ2.text
}
self.performSegue(withIdentifier: "Link6", sender: self)
}
这将从其他页面获取结果并将它们传递到具有“显示数据”按钮的页面,我只需要向其添加密码保护,以便只有密码持有者才能看到数据。
答案 0 :(得分:2)
您需要在文本字段中显示UIAlert Action,以从用户那里选择密码,并将文本与您从Coredata,钥匙串或API中获取的密码进行匹配。
带有文本字段代码的UIAlert是
let alertController = UIAlertController(title: "Test Title", message: "", preferredStyle: .alert)
alertController.addTextField { textField in
textField.placeholder = "Enter Password"
textField.isSecureTextEntry = true
}
let confirmActionBtn = UIAlertAction(title: "OK", style: .default) { [weak alertController] _ in
guard let alertController = alertController, let textField = alertController.textFields?.first else { return }
print("Password is \(String(describing: textField.text))")
// Just compare Entered String in textfield with your original password password
//if password is matched push or segue your required controller
}
alertController.addAction(confirmActionBtn)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)