ios - UITableView snap to cell -


i trying implement "snap cell" effect in uitableview. uitableview has 3 equally sized cells, reason uitableview snaps cell 0 or cell 1 , doesn't ever snap third cell. wrong 50 points low, no matter how hard slide. use obvious code create effect can't understand why doesn't work.

- (void)scrollviewwillenddragging:(uiscrollview *)scrollview withvelocity:(cgpoint)velocity targetcontentoffset:(inout cgpoint *)targetcontentoffset {     nsindexpath *pathfortargettopcell = [self.tableview indexpathforrowatpoint:cgpointmake(cgrectgetmidx(self.tableview.bounds), targetcontentoffset->y)];     dlog(@"indexpathforrow %d", pathfortargettopcell.row);     targetcontentoffset->y = [self.tableview rectforrowatindexpath:pathfortargettopcell].origin.y; } 

any thoughts going wrong?

edit: suspect has status bar , nav bar on top, since off 64 points. still doesn't explain why doesn't recognise last cell though..

for status bar offset, in vc's viewdidload:

if([self respondstoselector:@selector(setautomaticallyadjustsscrollviewinsets:)])    [self setautomaticallyadjustsscrollviewinsets:no]; 

edit

just testing, add 4 equally size cells , try snapping 3rd , 4th cells?

modify scrollviewwillenddragging implementation follows:

- (void)scrollviewwillenddragging:(uiscrollview *)scrollview withvelocity:(cgpoint)velocity targetcontentoffset:(inout cgpoint *)targetcontentoffset {      nsindexpath *pathforcentercell = [self.tableview indexpathforrowatpoint:cgpointmake(cgrectgetmidx(self.tableview.bounds), cgrectgetmidy(self.tableview.bounds))];      [self.tableview scrolltorowatindexpath:pathforcentercell atscrollposition:uitableviewscrollpositionmiddle animated:yes]; } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -