Encountered a strange error to display alert in Seque

141 Views Asked by At

I just want to check if the user enter any text into textview. if no text entered, I will prompt the user a message using alert using below code.

I am getting this strange error message:

Terminating app due to uncaught exception UIApplicationInvalidInterfaceOrientation, reason: ‘Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES’

override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
    if identifier =="MainSegueToVC2" {
        if txtView.Text.isEmpty {
            var alert = UIAlertController(title: "No Message", message: "Please enter some text", preferredStyle: UIlertControllerStyle.Alert)
            alert.AddAction(UIAlertAction(title:"OK", style:UIAlertActionStyle.Default,handler: nil))
            self.presentViewController(alert,animated: true, completion: nil)

            return false
        } else {
            return true
        }

        return true
    }

Override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier =="MainSegueToVC2") {
        --- code --
    }
}

---Update ---

I have this to make sure it is portrait mode:

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> Int {
    return UIInterfaceOrientation.Portrait.rawValue
}
0

There are 0 best solutions below