iPad - How do I load the first cell from the RootView automatically into the DetailView upon launch?

StackOverflow https://stackoverflow.com/questions/4651339

Question

The title pretty much asks it all. I've been coming back and trying to implement this every few days, but I cant seem to get it to work. I'd assume the code to set the detailItem from launch goes in the viewDidLoad, but at this point I am clueless.

Any help is greatly appreciated.

--Tyler

Was it helpful?

Solution

You can use the selectRowAtIndexPath delegate:

[tblMyTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];

Of course, replace [NSIndexPath indexPathForRow:0 inSection:0] with the section / row that you want to automatically set.

You can either put this in your viewDidLoad or viewWillAppear: delegate.

Also, make sure that you define your tblMyTable (or whatever you have named your table) in your header, hooked it up through Interface Builder (if your using a custom XIB), and use @synthesize in your .m

And the didSelectRowAtIndex: should be called when you use that method, so as long as your detailItem code is in didSelectRowAtIndex, you should be good.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top