1. Registration
Uikeyboarddidshownotification/uikeyboarddidhidenotification notice.
-(ID) Initwithnibname: (NSString*) Nibnameornil Bundle:nibbundleornil {if( Self= [SuperInitwithnibname:nibnameornil Bundle:nibbundleornil]) {//write here, or Viewdidload[[NsnotificationcenterDefaultcenter] Addobserver: SelfSelector@selector(Keyboardshown:) Name:uikeyboarddidshownotification object:Nil]; [[NsnotificationcenterDefaultcenter] Addobserver: SelfSelector@selector(Keyboardhidden:) Name:uikeyboarddidhidenotification object:Nil]; }return Self;} -(void) Dealloc {[[NsnotificationcenterDefaultcenter] Removeobserver: SelfName:uikeyboarddidshownotification object:Nil]; [[NsnotificationcenterDefaultcenter] Removeobserver: SelfName:uikeyboarddidhidenotification object:Nil];}
2. When the notification arrives, adjust frame.
-(void) Keyboardshown: (nsnotification*) Notification {_initialtvheight = _tableview. Frame. Size. Height;CGRectInitialframe = [[[Notification UserInfo] objectforkey:uikeyboardframeenduserinfokey] cgrectvalue];CGRectConvertedframe = [ Self. ViewConvertrect:initialframe Fromview:Nil];CGRectTvframe = _tableview. Frame; Tvframe. Size. Height= Convertedframe. Origin. Y; _tableview. Frame= Tvframe;} -(void) Keyboardhidden: (nsnotification*) Notification {CGRectTvframe = _tableview. Frame; Tvframe. Size. Height= _initialtvheight; [UIViewbeginanimations:@"Tableviewdown"ContextNULL]; [UIViewSetanimationduration:0.3F]; _tableview. Frame= Tvframe; [UIViewCommitanimations];}
3. Trigger text box, scroll tableview
-(void) textfielddidbeginediting: (Uitextfield *) TextField {
nsindexpath* path = [Nsindexpath indexpathforrow:row insection:section];
[Self performselector: @selector (Scrolltocell:) Withobject:path afterdelay:0.5f];
}
-(void) Scrolltocell: (nsindexpath*) path {
[_tableview Scrolltorowatindexpath:path Atscrollposition:uitableviewscrollpositionnone Animated:YES];
}
Reference:
1. http://blog.seancarpenter.net/2012/10/15/scrolling-a-uitableview-when-displaying-the-keyboard/
iOS soft keyboard masking UITableView text box issues