Scrolling UITableView to non-visible row workaround breaks with iOS 4.2 GM seed

The Scenario: - I have a plain tableView in a popover which constrains its height to four visible rows. When the popover view controller is initialized, the table datasource array may be populated with, for example, 10 elements. - My user has previously selected one of the 10 element values which persists in a core data object. - When the popover view controller is initialized, I match the user-selected core data value with the datasource array value and save the index to the row property of an NSIndexPath viewController property named selectedIndexPath. - Then when the table loads, I checkmark the cell at selectedIndexPath.row and scroll it to UITableViewScrollPositionTop.

The History: I never was able to get either tableView:scrollToRowAtIndexPath:atScrollPosition:animated: or scrollRectToVisible:animated: to accomplish this, either from the viewController viewWillAppear: or viewDidLoad methods. After great deal of searching and experimenting I found a workaround that did work. I called this method from viewController viewWillAppear:

(void)updateContentOffsetForTableView:(UITableView *)tbl withIndexPath:(NSIndexPath *)indexPath {

// Get rect of selected row from which to calculate origin point
CGRect rowRect = [tbl rectForRowAtIndexPath:indexPath];

// Get point of origin of selected row rect
CGPoint ptOffset = CGPointMake(rowRect.origin.x, rowRect.origin.y);

// Set tableView superclass scrollView.contentOffset property with selected row origin     
tbl.contentOffset = ptOffset;

 // Note: the cell checkmarking is done in tableView:cellForRowAtIndexPath:


passing the tableView and the selectedIndexPath property. Again, this worked as desired: for example, the 10th element in the datasource array would be matched with the core data value, the index saved to selectedIndexPath.row, and the above method called with the tableView and selectedIndexPath row, and the tableView would appear scrolled to contain the checkmarked row.

The Problem: With the 4.2 GM release, the desired scrolling does not work anymore - only the four tableView cells are displayed for the first four values in the datasource array. For the example, the cell in the 10th row will still be checkmarked as before, but scrolling that lower row into view will not be achieved.

Note that the workaround method previously only worked when called from viewWillAppear: and not from viewDidLoad. With the release of 4.2 GM seed, the above workaround no longer works.

This is in an iPad app. I am using the recently released Xcode 3.2.5 and iOS SDK 4.2 GM seed (Snow Leopard). I have verified that when I build for both iOS SDK 3.2 Simulator and Device, the above code works. When building for both iOS SDK 4.2 GM Simulator and Device, none of : the above code, tableView:scrollToRowAtIndexPath:atScrollPosition:animated:, or scrollRectToVisible:animated:, work to achieve scrolling the desired row into view.

Is this a bug? Any help or thoughts will be appreciated.


A suggestion by an Apple developer forums user provided a working solution:

This works for 4.2 GM seed, Simulator and Device, no longer depending on the UIScrollView.contentOffset hack.

In the view controller viewWillAppear: method:

(void)viewWillAppear:(BOOL)animated {
if (self.savedIndexPath) {
    [self performSelector:@selector(displayRowAtSelectedIndexPath:) withObject:self.savedIndexPath afterDelay:0.0];



(void)displayRowAtSelectedIndexPath:(NSIndexPath *)indexPath {

if (indexPath == self.savedIndexPath) {
    [self.myTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];


Need Your Help

I Want to do fb post same as foursquare api with map do(for checked in into venue). Any idea?

android ios facebook foursquare

I'm trying to achieve a facebook post as four square API does for check in into venue. Check in api deperecated and no luck with facebook open graph api. Can anyone help me in this regards?

Error consuming Web Service from Winform App - “Cannot execute a program…”

.net winforms web-services

I have a winform app that calls a web service to check for updates. This works in dev and it also works everywhere else I've tried it, just not on the installed copy on my machine (which happens t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.