views:

1440

answers:

4

I have created a UITableView and would like a specific UITableViewCell to appear selected (blue) when the view is loaded.

A: 

use UITableViewCells - (void)setSelected:(BOOL)selected animated:(BOOL)animated

method , info here http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell%5FClass/Reference/Reference.html#//apple%5Fref/occ/instm/UITableViewCell/setSelected:animated:

Daniel
Maybe following method suits better? http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableViewCell/setHighlighted:animated:
Harri Siirak
which method? the link doesnt go to any particular method
Daniel
O i f ound it, that one highlights it and does not select it, I guess if thats all the asker wants then sure thats more suitable
Daniel
+1  A: 

Be judicious using this method, as selecting the row in this way is something Apple suggests against doing to show a "chosen" state.

Instead, consider setting the cell's accessoryType property to something like UITableViewCellAccessoryCheckmark.

Shaggy Frog
I am trying to replicate the UI Apple use when you add/edit an event in the Calendar application and set a start and end date/time. I saw comments about the checkmark rule elsewhere, but am uncertain whether it would apply in this case (the table is used to layout components rather than present a list of data).
That's an interesting point. In this case, they don't need to have a subview for each the Starts and Ends since they are both representing the same kind of data, modified by the same kind of UIPickerView. So that would represent a judicious use. They are likely using UITableView's selectRowAtIndexPath:animated:scrollPosition: method... see http://tinyurl.com/yd9zs65
Shaggy Frog
A: 

Definitely watch out. I'm sure you have a good reason, but look closely at the Human Interface Guidelines document Apple provides. Apps get rejected for not unselecting table rows. I'd encourage you to find the appropriate section of the HIG and see Apple offers any suggestions.

marcc
+3  A: 
-(void)viewDidLoad:(BOOL)animated {
    // assuming you had the table view wired to IBOutlet myTableView
    // and that you wanted to select the first item in the first section
    [myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
}

I'm using this technique to select one of two cells so the users knows which cell a UIDatePicker below the table view it will effect. This technique is used by Apple in the calendar app when you create a new event and set the dates.

Hafthor