hellosheikh
hellosheikh

Reputation: 3015

IOS swift - How can I end the editing in textfield after opening a new view controller when textfield is tapped

hello I have a text field on my view controller. I am launching another view controller when user taps or click in the textfield. It is working successfully but the problem is when I press the back button from second view controller, It shows first controller and immediately it again redirect me to the 2nd view controller. screen doesn't stays on 1st controller. it is because cursor is there on the textfield so thats why.I don't no how can I make text field inactive after I move to the 2nd controller. hope you understand my question.

here is the code I am using

func textFieldShouldBeginEditing(textField: UITextField) -> Bool {

          self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("LoginViewController") as UIViewController, animated: true)
        //delegate method
        return true
    }

Upvotes: 1

Views: 1963

Answers (1)

Dharmbir Singh
Dharmbir Singh

Reputation: 17535

return false in the given method, it means your keyboard will not show and you will directly redirect to your 2nd viewcontroller.

          func textFieldShouldBeginEditing(textField: UITextField) -> Bool {

          self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("LoginViewController") as UIViewController, animated: true)
        //delegate method
        return false // Change here return false it means it won't show keyboard
    }

Upvotes: 4

Related Questions