IOS soft keyboard blocks text box issues in UITableView, iosuitableview
1. Registration
UIKeyboardDidShowNotification/UIKeyboardDidHideNotification notification.
-(Id) initWithNibName :( NSString *) nibNameOrNil bundle: nibBundleOrNil {if (self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]) {// write it here, alternatively, viewDidLoad [[nsicationcenter center defacenter center] addObserver: self selector: @ selector (keyboardShown :) name: jsonobject: nil]; [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (keyboardHidden :) name: jsonobject: nil];} return self;}-(void) dealloc {[[nsicationicationcenter defacenter center] removeObserver: self name: UIKeyboardDidShowNotification object: nil]; [[nsicationcenter center defacenter center] removeObserver: self name: UIKeyboardDidHideNotification object: nil];}
2. Adjust the frame when the notification arrives.
-(void) keyboardShown:(NSNotification*) notification { _initialTVHeight = _tableView.frame.size.height; CGRect initialFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect convertedFrame = [self.view convertRect:initialFrame fromView:nil]; CGRect tvFrame = _tableView.frame; tvFrame.size.height = convertedFrame.origin.y; _tableView.frame = tvFrame;}-(void) keyboardHidden:(NSNotification*) notification { CGRect tvFrame = _tableView.frame; tvFrame.size.height = _initialTVHeight; [UIView beginAnimations:@"TableViewDown" context:NULL]; [UIView setAnimationDuration:0.3f]; _tableView.frame = tvFrame; [UIView commitAnimations];}
3. Trigger the text box and scroll to tableView.
-(Void) textFieldDidBeginEditing :( UITextField *) textField {
NSIndexPath * path = [NSIndexPath indexPathForRow: row inSection: section];
[Self defined mselector: @ selector (scrollToCell :) withObject: path afterDelay: 0.5f];
}
-(Void) scrollToCell :( NSIndexPath *) path {
[_ TableView scrollToRowAtIndexPath: path atScrollPosition: UITableViewScrollPositionNone animated: YES];
}
Refer:
1. http://blog.seancarpenter.net/2012/10/15/scrolling-a-uitableview-when-displaying-the-keyboard/