When there is uitextview in the cell, the input text is required to move the TableView up, the basic practice is that the notification of the registration of keyboard changes in the method of notification to do tableview position adjustment,
One, general practice
-(void) Registerforkeyboardnotifications {
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwasshown:) Name: Uikeyboarddidshownotification Object:nil];
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillbehidden:) Name: Uikeyboardwillhidenotification Object:nil];
NSLog (@ "register");
}
-(void) Keyboardwasshown: (nsnotification *) anotification {
nsdictionary* info = [Anotification userInfo];
Cgsize kbsize = [[info objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue].size;
Adjust the padding
Uiedgeinsets contentinsets = uiedgeinsetsmake (0.0, 0.0, kbsize.height, 0.0);
}
-(void) Keyboardwillbehidden: (nsnotification *) anotification {
Uiedgeinsets contentinsets = Uiedgeinsetszero;
}
Today, the project found that the above methods have some defects, when the tableview have more than one group, there is a group of cells do not follow the upward movement as follows:
When the keyboard appears, the tail view moves up but the cell in this group does not move up, which is why I haven't figured it out yet.
There are also problems with these methods
The solution found is to find the first responder in the notification method that appears on the keyboard (typically: Uitextfield), to determine if the cell it is in is visible, and if not, let TableView slide to the cell all visible:
#pragma mark keyboard appears
-(void) Keyboardwillshow: (nsnotification *) Note 
{
CGRect keyboardrect=[note.userinfo[uikeyboardframeenduserinfokey] cgrectvalue];    
Get the first responder
UIWindow * Keywindow = [[uiapplication sharedapplication] Keywindow];  
UIView *activefield = [Keywindow performselector:@selector (FirstResponder)];    
Page display area after the keyboard is removed
CGRect arect = self .  View. frame;   
Arect. size. height = arect.  Size. Height-keyboardrect. size. height-up ;       
Determine if the cell bottom is within the display range
Cgpoint cellbottompoint = cgpointmake(0.0, Activefield.superview. Superview. Frame. Origin. Y +activefield.superview. Superview. Frame. Size. Height);    
if (!  Cgrectcontainspoint (Arect, Cellbottompoint)) { 
Self . TableView. Contentinset = Uiedgeinsetsmake (0, 0, Keyboardrect.  Size. height, 0);        
cgpoint scrollpoint = cgpointmake (0.0, cellbottompoint.  Y-arect. size. Height----);      
[_tableview setcontentoffset:scrollpoint animated:YES];   
}
}
#pragma mark keyboard disappears
-(void) Keyboardwillhide: (nsnotification *) Note 
{
[UIView animatewithduration:. animations: ^{     
Self . TableView. Contentinset = Uiedgeinsetsmake (0, 0,  0);       
}];
}
This is the perfect solution to the above problems;
When there is uitextfiled or Uitextview in the cell, the keyboard pops up tableview, but some cells do not move