-2

I am trying to dismiss keyboard in text view using accessory views with done button but keyboard is not showing done button in it.Actually i have writen my code in textViewDidBeginEditing using inputAccessoryView.Here is my code.

func textViewDidBeginEditing(textView: UITextView) { currentTextView = textView //This is to tell the current position in text view

    var indexPath:NSIndexPath = NSIndexPath(forRow: 0, inSection: 2)
    let cell:EventTableTableViewCell = EventTableview.cellForRowAtIndexPath(indexPath) as! EventTableTableViewCell
    cell.messageTextView.autocorrectionType = UITextAutocorrectionType.No


    let keyboardDoneButton = UIToolbar()
    keyboardDoneButton.sizeToFit()

    let item = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("doneButton"))



    var toolbarButtons = [item]
    //Put the buttons into the ToolBar and display the tool bar
    keyboardDoneButton.setItems(toolbarButtons, animated: false)
        keyboardDoneButton.userInteractionEnabled = true

//cell.messageTextView.inputAccessoryView = keyboardDoneButton
    textView.inputAccessoryView = keyboardDoneButton

    }


}
func doneButton()
{
UIApplication.sharedApplication().sendAction("resignFirstResponder", to:nil, from:nil, forEvent:nil)

}
swapna
  • 1
  • 2
  • You are going to need to update your question with some more details if you want to get any useful help. – rmaddy Jun 30 '15 at 16:42
  • You need to set the done button as part of the keyboard – Aggressor Jun 30 '15 at 16:43
  • possible duplicate of [hide keyboard for text field in swift programming language](http://stackoverflow.com/questions/24908966/hide-keyboard-for-text-field-in-swift-programming-language) – Sujay Jun 30 '15 at 16:47

2 Answers2

0
_textView.returnKeyType = UIReturnKeyType.Done
Aggressor
  • 13,323
  • 24
  • 103
  • 182
0

Did you set the keyboard in IB? Storyboard > Textfield > Attributes Inspector > Return Key > Done

Implement the delegate method:

- textfieldShouldReturn:

Found here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/#//apple_ref/occ/intfm/UITextFieldDelegate/textFieldShouldReturn: