0

I have UIViewController(FirtViewController) in my Storyboard... In Swift file assigned to this UIViewController i add custom UIView

let customView = NSBundle.mainBundle().loadNibNamed("CustomView", owner: self, options: nil)[0] as! CustomView
self.view.addSubview(customView)

In this customView i have a textField. In swift file assigned to this customView i have function:

func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true      
}

But when i pressed "return key" my keyboard don't hide!

Where is my mistake?

Dmitry
  • 2,963
  • 2
  • 21
  • 39

1 Answers1

3

Wherever you added customView:

customView.textField.delegate = self

Next, on the line of FirstViewController's declaration, add conformance to UITextFieldDelegate.

Then, put the textFieldShouldReturn: in the view controller.

tktsubota
  • 9,371
  • 3
  • 32
  • 40
  • when i add this code i have a error: Cannot assign value of type FirstViewController to type UITextFieldDelegate? – Dmitry Feb 13 '16 at 23:23