iphone - UITableView scrolls too far when editing embedded UITextView -



iphone - UITableView scrolls too far when editing embedded UITextView -

i've embedded uitextview within uitableviewcell, , of table working fine. however, when enable editing on uitextview , start editing, table shifts far, obscuring cursor. there way command how far tableview scrolls? manually scrolling view cell works, view still scrolls before scrolling downwards , view.

here illustration of mean: editing uitextfield - field neatly placed straight above keyboard. http://imageshack.us/photo/my-images/13/textfield.png/

editing uitextview - field placed above keyboard removing toolbar keyboard doesn't impact anything) http://imageshack.us/photo/my-images/809/textview.png/

here's code relevant uitextview in uitableviewcontroller object:

- (void)viewdidload { [super viewdidload]; self.navigationitem.rightbarbuttonitem = self.editbuttonitem; [[nsnotificationcenter defaultcenter] addobserver: self selector: @selector(keyboardwillshow:) name: uikeyboardwillshownotification object:nil]; [[nsnotificationcenter defaultcenter] addobserver: self selector: @selector(keyboardwillhide:) name: uikeyboardwillhidenotification object:nil]; } - (bool)textviewshouldbeginediting:(uitextview *)textview { viewtargetedforediting = (uiview *)textview; homecoming yes; } - (void)textviewdidbeginediting:(uitextview *)textview { [self.navigationcontroller setnavigationbarhidden:yes animated:yes]; // shrink textview fit on-screen originaltextviewframe = textview.frame; cgrect keyboardrect = [[keyboarduserinfo objectforkey:uikeyboardframeenduserinfokey] cgrectvalue]; cgfloat keyboardheight = keyboardrect.size.height; cgrect newviewframe = textview.frame; cgfloat spaceabovekeyboard = self.containerview.frame.size.height - keyboardheight; newviewframe.size.height = (spaceabovekeyboard < textview.frame.size.height) ? spaceabovekeyboard : textview.frame.size.height; /* animate calculations */ [uiview beginanimations:nil context:null]; [uiview setanimationduration:[[keyboarduserinfo objectforkey:uikeyboardanimationdurationuserinfokey] doublevalue]]; textview.frame = newviewframe; [uiview commitanimations]; // recalculate keyboard height, in case aren't in portrait mode cgfloat toolbarheight; if (uiinterfaceorientationisportrait(self.interfaceorientation)) { toolbarheight = 44.0; } else { toolbarheight = 32.0; } cgrect frame = textview.inputaccessoryview.frame; frame.size.height = toolbarheight; } - (void)endtextviewediting { [viewtargetedforediting resignfirstresponder]; } - (void)textviewdidendediting:(uitextview *)textview { [self.navigationcontroller setnavigationbarhidden:no animated:yes]; } #pragma mark - keyboard notifications - (void)keyboardwillshow:(nsnotification *)notification { [keyboarduserinfo release]; keyboarduserinfo = [[notification userinfo] retain]; [self viewdidbeginediting:viewtargetedforediting]; } - (void)keyboardwillhide:(nsnotification *)notification { [keyboarduserinfo release]; keyboarduserinfo = [[notification userinfo] retain]; [self viewdidendediting:viewtargetedforediting]; } - (void)viewdidbeginediting:(id)aview { // called 2nd uitableviewcell *cell = (uitableviewcell *)[aview superview]; [self.tableview scrolltorowatindexpath:[self.tableview indexpathforcell:cell] atscrollposition:uitableviewscrollpositiontop animated:yes]; } - (void)viewdidendediting:(id)aview { nsindexpath *indexpath = [self.tableview indexpathforcell:(uitableviewcell *)[viewtargetedforediting superview]]; gallupappdelegate *appdelegate = (gallupappdelegate *)[[uiapplication sharedapplication] delegate]; switch (indexpath.section) { case sectiondescription: if (![[(uitextfield *)aview text] isequaltostring:self.plan.description]) { self.plan.description = [(uitextfield *)aview text]; [appdelegate savemanagedcontext]; } break; case sectionnotes: if (![[(uitextview *)aview text] isequaltostring:self.plan.notes]) { self.plan.notes = [(uitextview *)aview text]; [appdelegate savemanagedcontext]; } break; case sectionlocation: if (![[(uitextfield *)aview text] isequaltostring:self.plan.location]) { self.plan.location = [(uitextfield *)aview text]; [appdelegate savemanagedcontext]; } break; } }

the textviewcell subclass of uitableviewcell, , cell giving me problem scrolling.here's implementation:

@implementation textviewcell @synthesize contents=_contents; - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { _contents = [[uitextview alloc] initwithframe:cgrectzero]; [self addsubview:_contents]; self.contents.font = [uifont systemfontofsize:17]; self.contents.datadetectortypes = uidatadetectortypeall; cgrect frame = cgrectmake(0, 0, self.window.frame.size.width, 44.0); uibarbuttonitem *spacer = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil]; uibarbuttonitem *done = [[uibarbuttonitem alloc] initwithtitle:@"done" style:uibarbuttonitemstyledone target:self action:@selector(endtextviewediting)]; uitoolbar *textviewtoolbar = [[uitoolbar alloc] initwithframe:frame]; textviewtoolbar.barstyle = uibarstyleblackopaque; [textviewtoolbar setitems:[nsarray arraywithobjects:spacer, done, nil]]; self.contents.inputaccessoryview = textviewtoolbar; } homecoming self; } - (void)endtextviewediting { [self.contents resignfirstresponder]; } #define left_margin 15 #define top_margin 5 - (void)layoutsubviews { [super layoutsubviews]; cgfloat width = self.frame.size.width - (left_margin *2); cgfloat height = self.frame.size.height - (top_margin *2); self.contents.frame = cgrectmake(left_margin, top_margin, width, height); } - (void)setselected:(bool)selected animated:(bool)animated { //[super setselected:selected animated:animated]; // configure view selected state } - (void)dealloc { [super dealloc]; } @end

as turns out, subclassing uitableview , implementing next fixed problem:

- (void)setcontentoffset:(cgpoint)contentoffset animated:(bool)animated { [super setcontentoffset:contentoffset animated:animated]; return; static int = 0; if (0 == i) { i++; } else { = 0; [super setcontentoffset:contentoffset animated:animated]; } return; }

apparently -setcontentoffset:animated: message sent 2x, , if first 1 allowed run sec time round doesn't it's job properly.

does have insite why prepare problem?

iphone uitableview uitextview

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -