当我在文本字段中测试不良数据并尝试显示缺失或不良数据警报时,不显示警报。但是,我可以得到一个警报在viewDidLoad中功能提醒iOS swift
这里显示的是代码
import UIKit
import CoreData
class SellViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var customer: UITextField!
@IBOutlet weak var bales: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let alert = UIAlertController(title: "Hey", message: "@ SellViewController viewDidLoad ", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
func checkDataInput(){
print("checking data input customer.text \(customer.text)")
print("checking data input bales.text \(bales.text)")
if (customer.text!.isEmpty) {
customer.text = "REQUIRED"
missingCustomer()
}
if (bales.text!.isEmpty){
availableAlert()
}else{
newQuantity = Int(bales.text!)!
}
func availableAlert() {
print(" at availableAlert")
let alert = UIAlertController(title: "Hey", message: "@ SellViewController func missingValues ", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
func missingCustomer() {
print(" at missingCustomer")
let alert = UIAlertController(title: "Hey", message: "@ SellViewController func missingCustomer ", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Working!!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
这在viewDidLoad中显示警报,但当时我已经丢失的数据没有任何警报。我缺少数据时的打印语句返回为。
检查数据输入customer.text可选( “”)
检查数据输入bales.text可选( “”)
在missingCustomer
在availableAlert
致命错误:意外地发现零而展开的可选值
发生致命错误的原因是用户在得到警报时无法纠正其响应。
我在做什么错?当我的 missingData函数被触发并且能够更正它们的条目时,不应该立即显示警报吗?
为什么不发布相关代码,因为这是您的问题所在? – rmaddy
在主线程上执行'missingData'函数吗?如果没有,请使用'DispatchQueue.main.async {/ *在这里显示您的提醒* /}'(或'dispatch_async(dispatch_get_main_queue()){/ *在Swift 2.0中显示您的提醒* /}') – Palle