0

我在另一个表视图的一行中有一个表视图。在我的内部表格视图的 cellforRowat 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
        }
    }
}
4

0 回答 0