ios - UIAlertController in swift -
i creating view controller
in swift few text fields , accept button
confirms user's input. accept button
checks if of text fields empty. if so, pop alert
saying it cannot empty
. if not empty, store input , jump view.
i created separated function called checempty()
looks this:
func checempty(title: string, object: uitextfield) -> (bool) { if object.text.isempty { let alertcontroller = uialertcontroller(title: "invalid input", message:"\(title) cannot empty", preferredstyle: uialertcontrollerstyle.alert) alertcontroller.addaction(uialertaction(title: "dismiss", style: uialertactionstyle.default) self.presentviewcontroller(alertcontroller, animated: true, completion: nil) return false } else { return true } }
and call function in acceptbutton
action:
@ibaction func acceptbutton(sender: uibutton){ if(checempty("event", object: eventname) && checempty("priority", object: priority) { //if not empty, confirm user input // ... }
when run it, alert message works fine reason console shows this:
2015-08-03 12:11:50.656 finishittoday[13777:688070] >'s window not equal 's view's window!
can tell me why warning appears? thank much!
ps. want if of text field empty, show alert , stay @ same page. if none of them empty, perform segue , switch view. code above works fine except warning.
here working code:
import uikit class viewcontroller: uiviewcontroller { @iboutlet weak var eventname: uitextfield! @iboutlet weak var priority: uitextfield! @ibaction func acceptbutton(sender: uibutton){ if checempty("event", object: eventname) && checempty("priority", object: priority){ println("both text fields empty") } } func checempty(title: string, object: uitextfield) -> (bool) { if object.text.isempty { var alert = uialertcontroller(title: "invalid input", message: "\(title) cannot empty", preferredstyle: uialertcontrollerstyle.alert) alert.addaction(uialertaction(title: "dismiss", style: .cancel, handler: { action in println("click of cancel button") })) self.presentviewcontroller(alert, animated: true, completion: nil) return false } else { return true } } }
Comments
Post a Comment