views:

60

answers:

2

I am using a splitviewcontroller. When I select something in the table the row is highlighted and it is shown in the detailed view. I have also provided an option to change the contents in the detailed view by scrolling.

When I start I want the the 5th row to be highlighted by itself, how can I do it?

A: 

Check out the following UITableView method:

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
David
Ya, I was trying to make it call somehow. Wrote it inside the viewDidLoad like this. But its crashing. NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:5 inSection:0]; [self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
wolverine
A: 

I was using the above function from the start. But the app was crashing when I wrote this code into the viewDidLoad.

NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:5 inSection:0];
[self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; 

There is no data loaded into the UITableView instance. You can't select a row that doesn't exist. This was the reason it was crashing. And yes, this is the function that will help us do it.

wolverine
Yes, you are right, the data is not yet loaded into the table view, there is no cell at index path (5,0).Try calling it inside `- (void)viewDidAppear:(BOOL)animated;` instead, it should work.
David