how to pre-select a row in a UItableView [duplicate]
Possible Duplicate:
how to set row selected by default in UITableView
Hello, i use this method to get the selected row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@" champ séléctionner : %d ",indexPath.row);
if(segment.selectedSegmentIndex==0)
{
depSelectedIndice=indexPath.row;
}
else if(segment.selectedSegmentIndex==1) {
comSelectedIndice=indexPath.row;
}
can i , when i reload the table, select a row from the number depSelectedIndice or comSelectedIn开发者_开发百科dice ? thank you
You could try selectRowAtIndexPath:animated:scrollPosition:. To pass in an IndexPath you can use:
[NSIndexPath indexPathForRow:depSelectedIndice inSection:0]
or
[NSIndexPath indexPathForRow:comSelectedIndice inSection:0]
So all together you do:
[yourTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:depSelectedIndice inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone]
精彩评论