views:

106

answers:

0

I used to have the following snippet of code in viewWillAppear method of a tableviewcontroller. What it essentially did was to start with the first row selected when the view was loaded.

// Select the first row by default and set the datePicker
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView 
    selectRowAtIndexPath:indexPath
    animated:NO
    scrollPosition:UITableViewScrollPositionNone];

In SDK 3.0, this stopped working. I tried moving it in datasource method tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath with no success.

Finally, I moved it into viewDidAppear and it now seems to work but with one small glitch.

Since the selection is done after the view has already appeared, a slight flicker is visible when the row is selected. When I enable animation, the selection is smooth but it takes time for the selection to appear.

  1. What has changed from SDK 2.2.1 to SDK 3.0 to break this functionality?
  2. Is there any better way to implement it than putting this code in viewDidAppear, so that the cell will appear pre selected?