I have a table view with a text field and a textview. I've implemented this code like suggested by this apple sample code https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
@IBOutlet var myTableView: UITableView
func keyboardWasShown (notification: NSNotification)
{
println("keyboard was shown")
var info = notification.userInfo
var keyboardSize = info.objectForKey(UIKeyboardFrameBeginUserInfoKey).CGRectValue().size
myTableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardSize.height, 0)
myTableView.scrollIndicatorInsets = myTableView.contentInset
}
func keyboardWillBeHidden (notification: NSNotification)
{
println("keyboard will be hidden")
myTableView.contentInset = UIEdgeInsetsZero
myTableView.scrollIndicatorInsets = UIEdgeInsetsZero
}
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeHidden:", name: UIKeyboardWillHideNotification, object: nil)
}
When i click on the "text" of the scroll view go just above the top of the screen, but when i release the keyboard it remains scrolled up. It's just like the insets property can't be modified after the first time. What's my mistake?