Reputation: 15055
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
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