我有一个警报控制器,应该在用户在文本字段中输入不正确数量的字符后出现。警报控制器根本没有出现。 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