0

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

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
Tyler Bell
  • 61
  • 7

1 Answers1

2

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.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • What would the tblMyTable be if I am using the prebuilt table of the RootViewController? I've tried synthesizing the tableView from the TableViewContoller to use it, but I get "UITableView may not respond to '-didSelectRowAtIndexPath' warning. Thanks. – Tyler Bell Jan 11 '11 at 15:49
  • Okay, I got the first cell to load in the DetailView just by setting the detailItem to the objectAtIndex:0. It loads the data from the RootView just fine, but it doesn't select the cell where it's coming from in the RootView. Is there a way to select/enable a single cell without getting any of it's data (just highlight it)? – Tyler Bell Jan 11 '11 at 15:51
  • Apple frowns upon keeping the cell highlighted. – WrightsCS Jan 11 '11 at 15:59
  • You may be able to use something like this: `[tblMyTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];` Just make sure you have your selection style set. I personally like to make custom colors for my tables, so I usually control the selection highlighting by changing the background color of the cell the user presses and setting the default selection type to none... – gabaum10 Jan 11 '11 at 16:12