获取UITableView的选定索引

我想选择
UITableView
的索引。 我写了以下代码:
NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
[tableView scrollToRowAtIndexPath:index 
                 atScrollPosition:UITableViewScrollPositionTop 
                         animated:YES];
这总是适用于第一项。我想在
indexPathForRow.
中选择索引 请帮忙。 谢谢。     
已邀请:
NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];
    
获取当前选定的行。 如果您只有一个部分,可能会有所帮助。
- (NSUInteger)currentSellectedRowIndex
{
    NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
    if (selectedIndexPath) {
        return selectedIndexPath.row;
    }
    else {
        return NSNotFound;
    }
}
    
使用此代码
CGPoint location =[sender locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell *swipedCell  = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
NSIndexPath *indexPath = [self.tableView indexPathForCell:swipedCell];
    
在didSelectRowAtIndexPath中,将声明为NSIndexPath的接口设置为返回的索引路径。然后您可以滚动到该变量。如果您需要帮助,请发表评论并提供一些示例代码。     
Swift 4.2
let selectedIndexPath = tableView.indexPathForSelectedRow
这是一个可选的返回值。     

要回复问题请先登录注册