我有一個警報控制器,應該在用戶在文本字段中輸入不正確數量的字符後出現。警報控制器根本沒有出現。 WUIAlertController not displayed
func usernameFieldCharacters() {
let alertController = UIAlertController(title: "Alert", message: "Five characters or more is required in all fields" , preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "OK", style: .Default) {
action -> Void in // Does not do anything
}
alertController.addAction(okAction) // adds the OK button to
// to alert controller
let allowedChars = 5 // character amount has to be equal or greater in each field
let usernameCount = theUsernameField.text?.characters.count
if usernameCount < allowedChars {
self.presentViewController(alertController, animated: true, completion: nil)
} else {
alertController.viewDidAppear(false)
}
}
你不應該需要調用'viewDidAppear'法第所有。然後檢查**主線程中提供的alertController ** – ridvankucuk