我有一个 UISearchController,我想在单击键盘上的搜索按钮时选择 searchResultsController tableview 的第一行。 为此,我尝试实现
-(void)searchButtonClicked:(UISerachBar*)searchBar {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.searchResultsController.tableView selectRowAtIndexPath: indexPath animated:false scrollPostion:UITableViewScrollPositionNone];
[self.searchResultsController tableview:self.searchResultsController.tableView didSelectRowAtIndexPath: indexPath];
}
但它对我不起作用!!
然后我尝试做一个单独的方法:
-(void) plotPinOnMapWithIndexPath:(NSIndexPath*)indexpath;
并通过传递 indexPaths 在 didSelectRowAtIndexPath
和 searchButtonClicked
方法中调用它。但问题是单元格没有像它获取的那样突出显示当用户点击它时突出显示。
最佳答案
这对我有用,而且是正确的:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
可选地试试这个:
[self.tableView:self.tableView didSelectRowAtIndexPath:indexPath];
或者您可以使用 Segue 继续结果:
[self performSegueWithIdentifier:"showDetailView" sender:self];
在 prepareForSegue 方法中你传递参数....
关于ios - 如何以编程方式选择 uitableview 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31204365/