Thursday, 15 March 2012

uitableview - uitextfields with tableview keyboard avoiding when tableview scrolling disabled -



uitableview - uitextfields with tableview keyboard avoiding when tableview scrolling disabled -

i have 10 textfields on tableview tableview scrolling disabled.

how handle keyboard avoiding textfields.

the next have tried with

// register notification when keyboard show

[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwasshown:) name:uikeyboardwillshownotification object:nil]; // register notification when keyboard hide [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(keyboardwillbehidden:) name:uikeyboardwillhidenotification object:nil];

pragma mark - keyboard notification (called when uikeyboarddidshownotification sent.)

- (void)keyboardwasshown:(nsnotification*)anotification { nsdictionary* info = [anotification userinfo]; cgsize kbsize = [[info objectforkey:uikeyboardframebeginuserinfokey] cgrectvalue].size; uiedgeinsets contentinsets = uiedgeinsetsmake(0.0, 0.0, kbsize.height, 0.0); guestrechargetableview.contentinset = contentinsets; guestrechargetableview.scrollindicatorinsets = contentinsets; // if active text field hidden keyboard, scroll it's visible // app might not need or want behavior. cgrect arect = self.view.frame; arect.size.height -= kbsize.height; if (!cgrectcontainspoint(arect, activefield.frame.origin) ) { [guestrechargetableview scrollrecttovisible:activefield.frame animated:yes]; } }

// called when uikeyboardwillhidenotification sent

- (void)keyboardwillbehidden:(nsnotification*)anotification { uiedgeinsets contentinsets = uiedgeinsetszero; guestrechargetableview.contentinset = contentinsets; guestrechargetableview.scrollindicatorinsets = contentinsets; }

this working not proper when selecting on textfield , moves up.provide solution or other alternative answer..

happy coding....

uitableview keyboard textfield tpkeyboardavoiding

No comments:

Post a Comment