Daniel G. Wilson
Daniel G. Wilson

Reputation: 15055

NSTableView - Pre-Hilight a certain row

Hey all, I have a table where the user can select a preferred sound, but one should be already preselected.

I know the row number that should be preselected, however, I do not know the index number. How would I get that?

Cheers all, Merry Xmas.

Upvotes: 1

Views: 1157

Answers (1)

James Eichele
James Eichele

Reputation: 119164

The NSIndexPath class provides a handy method to provide the index for a given row and section: +indexPathForRow:inSection:

You could use it as follows:

- (void)selectRow:(NSUInteger)rowNum inTableView:(UITableView *)tableView
{
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:rowNum
                                                 inSection:0];
    [tableView selectRowAtIndexPath:indexPath
                           animated:YES
                     scrollPosition:UITableViewScrollPositionMiddle];
}

Upvotes: 1

Related Questions