ios - UITableView Not Scrolling after contentInset -


i'm working on project have tableview , uitextfield.

i'm applying following method when uitextfield gain/loose focus :

-(void)enableinset {  cgfloat offset = -30.0f; uiedgeinsets inset = uiedgeinsetsmake(placesmapview.frame.size.height - offset, 0.0f, 0.0f, 00.f);  // updating tableview position. placestableview.contentinset = inset; placestableview.contentoffset = cgpointmake(0.0f, -(placesmapview.frame.size.height - offset)); placestableview.scrollindicatorinsets = inset; } 

and

- (void)disableinset { cgfloat offset = self.navigationcontroller.navigationbar.frame.size.height  + [uiapplication sharedapplication].statusbarframe.size.height; uiedgeinsets inset = uiedgeinsetsmake(offset, 0.0f, 0.0f, 00.f); placestableview.contentinset = inset; placestableview.contentoffset = cgpointmake(0.0f, -offset); placestableview.scrollindicatorinsets = inset; } 

the enableinset method called in viewdidlayoutsubviews. when call disableinset , enableinset, uitableview can not scrolled anymore.

what did did wrong ? idea can answer ?

edit : if can help, added project on github :

https://github.com/loadex/placeviewer

to re-produce bug : scroll list, tap on search bar, hit cancel, try scroll again list.

weirdly click on filter button, when uiactionsheet dismissed, scroll working again.

while looking solution problem noticed bottom part of contentinset of placestableview kept changing through different states. 0 when in initial state see map, , tableview behaving expected. got set 216 when keyboard came after tapping search field. figured automated communication between tableview , keyboard (through notifications or did in placesquerytableviewcontroller). fine because want bottom inset set top of keyboard when appears. now, here comes buggy part. when tapped cancel button, contentinset.bottom got set -216.

i can't quite explain why happens, suspect has how automatic change of inset implemented. suspect tableview.contentinset.bottom -= heightofkeyboard, , happens when animation finished, , not before. source of problem change bottom of contentinset before animation done, , before automatic change has happened. you're setting bottom 0 user taps cancel. system comes in , reduces height of keyboard, turns out 216. that's think happening anyway.

to fix problem, avoid changing bottom part of contentinset , change top part. placestableview.contentinset.top readonly, if in code below, can around that. have changed 2 lines of code in each method, ones have inset. see did.

-(void)enableinset { nslog(@"enabling insets"); // setting tableview overlay map view cgfloat offset = [placestableviewcontroller tableview:placestableviewcontroller.tableview heightforrowatindexpath:nil] - 30.0f; uiedgeinsets inset = placestableview.contentinset; // uiedgeinsetsmake(placesmapview.frame.size.height - offset, 0.0f, 0.0f, 0.0f); inset.top = placesmapview.frame.size.height - offset;  // updating tableview position. placestableview.contentinset = inset; placestableview.contentoffset = cgpointmake(0.0f, -(placesmapview.frame.size.height - offset)); placestableview.scrollindicatorinsets = inset;  placesmapview.hidden = no; [placestableviewcontroller loadobjects];}   - (void)disableinset { nslog(@"disable insets"); cgfloat offset = self.navigationcontroller.navigationbar.frame.size.height  + [uiapplication sharedapplication].statusbarframe.size.height; uiedgeinsets inset = placestableview.contentinset;// uiedgeinsetsmake(offset, 0.0f, 0.0f, 0.0f); inset.top = offset;  placestableview.contentinset = inset; placestableview.contentoffset = cgpointmake(0.0f, -offset); placestableview.scrollindicatorinsets = inset;  // hidding map while in search placesmapview.hidden = yes;} 

.

btw, if want know how found contentinset values @ different states, it's quite simple. did set myself delegate of placestableview in - (void)viewdidload placestableview.delegate = self;. had change @interfacestatement @interface krackmapviewcontroller () <uitableviewdelegate> conform uitableviewdelegate. now, here's trick: uitableviewdelegate conforms uiscrollviewdelegate. means can implement methods of scroll view delegate. 1 particularly interesting one:

- (void)scrollviewwillbegindragging:(uiscrollview *)scrollview { nslog(@"did scroll insettop: %f, insetbottom: %f, contentoffset: %f", placestableview.contentinset.top, placestableview.contentinset.bottom, placestableview.contentoffset.y); }

that lets know when start dragging tableview, , in there nslog out different parameters.

i hope helpful. let me know if works you.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -