Ios IndexPathForRow(at:point)每次返回0

Ios IndexPathForRow(at:point)每次返回0,ios,swift,tableview,indexpath,Ios,Swift,Tableview,Indexpath,我在另一个tableview的一行中有一个tableview。在内部表视图的cellforRowat indexPath中,我希望能够获得out表视图的indexPath 我试过: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if let cell = tableView.dequeueReusableCell(withIdenti

我在另一个tableview的一行中有一个tableview。在内部表视图的cellforRowat indexPath中,我希望能够获得out表视图的indexPath

我试过:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if let cell = tableView.dequeueReusableCell(withIdentifier: "Answer") as? MCAnswerCell
    {
        if let index = self.tableView?.indexPath(for: self){
            // self is a custom cell used in the outer tableview
        }
    }
}
但对于不在屏幕上的行,它返回nil。因此,我将尝试使用以下方法:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if let cell = tableView.dequeueReusableCell(withIdentifier: "Answer") as? MCAnswerCell
    {
        if let index = self.tableView?.indexPathForRow(at: cell.center){
            //returns 0 every time
        }
    }
}

每个单元格中是否都有一个tableview,或者它只是一个单元格?您想做什么?为什么要在cellForRowAtIndexPath中建立索引…而不是使用IndexPath.row。对单元格进行分组的最简单、最有效的方法是创建多个节。然后,您将通过indexPath.section访问该节。在这种情况下,请在内部单元格的自定义UiTableViewCell类中创建一个可选变量。当单元格应该有表时,将indexPath分配给该变量。当从内部表的单元格中读取时,只需读取变量的值