大家好,我有一个表格,用户可以在其中选择首选声音,但应该已经预先选择了一个。
我知道应该预选的行号,但是我不知道索引号。我怎样才能得到它?
干杯,圣诞快乐。
最佳答案
NSIndexPath
类提供了一个方便的方法来为给定的行和部分提供索引:+ indexPathForRow:inSection:
您可以按如下方式使用它:
- (void)selectRow:(NSUInteger)rowNum inTableView:(UITableView *)tableView
{
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:rowNum
inSection:0];
[tableView selectRowAtIndexPath:indexPath
animated:YES
scrollPosition:UITableViewScrollPositionMiddle];
}
关于xcode - NSTableView - 预高亮某一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4480400/