开发者

how to pre-select a row in a UItableView [duplicate]

This question already has answers here: Closed 11 years ago.

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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜