1

I have a simple UITableView; I'm trying to force it to scroll to a certain position in viewDidLoad, so I can hide the first row in my table (unless a user scrolls up). My first row is 90.0px in height, so I'm trying this to force my UITableView to scroll:

[contentTable setContentOffset: CGPointMake(0, 90.0f) animated: NO];

The problem is that using animated: NO does nothing; the UITableView will not scroll. If I use animated: YES, however, things work just fine; it scrolls, but the downside to having it animated is that my UI appears to flash during the scroll, which is not what I want at all.

Any ideas why? It doesn't seem to matter if my UITableView has 1 row or 20 rows, it will only scroll if I pass animated: YES to setContentOffset.

I am currently running Xcode 4.2 and I'm using iOS 4.3.3 on my first-gen iPad.


Edit: One other thing to mention - scrollToRect doesn't seem to work at all, regardless of what value I pass for it's animated property. Is there something I'm fundamentally misunderstanding about scrolling on iOS?

Rob
  • 25,984
  • 32
  • 109
  • 155
  • possible duplicate of [UITableView won't scroll to certain position](http://stackoverflow.com/questions/3722994/uitableview-wont-scroll-to-certain-position) – Rob Aug 14 '11 at 16:24

2 Answers2

1

Potential duplicates:

setContentOffset only works if animated is set to YES

UITableView won't scroll to certain position

Community
  • 1
  • 1
Sergnsk
  • 3,305
  • 3
  • 23
  • 28
0

I'm pretty sure there's something buggy about UITableView scrolling. I'm using:

selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle

It's supposed to select the row indicated by indexPath and then scroll the table so the selected row is in the middle of the view. It reliably works that way on the simulator but on the iPhone it sometimes scrolls and sometimes doesn't. Often (but not always) it works the first few times and then stops working (i.e., it doesn't scroll and the selected cell is off screen). But the correct cell is always selected. I haven't been able to pin down what governs whether it scrolls or not. I submitted a bug report to Apple but no response.

RobertL
  • 14,214
  • 11
  • 38
  • 44