Ios 按表索引单元格数据更改导航标题文本

Ios 按表索引单元格数据更改导航标题文本,ios,iphone,swift,Ios,Iphone,Swift,我已经实现了启用分页的表视图,单元格大小是设备屏幕大小,我想做的是在表单元格完全滚动时,通过索引数据更改导航栏标题 func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { let doseData = topDoseData[indexPath.row] self.navigationItem.title =

我已经实现了启用分页的表视图,单元格大小是设备屏幕大小,我想做的是在表单元格完全滚动时,通过索引数据更改导航栏标题

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    let doseData = topDoseData[indexPath.row]
    self.navigationItem.title = doseData.value(forKey: "posted_on") as? String
}

如果一切都按预期设置,那么问题可能出在您的数据中。您可以展开可选值以查找遗漏的位置。你可以试试

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    guard let navigationController = self.navigationController else {
        fatalError("navigationController has not been set yet")
    }

    let doseData = topDoseData[indexPath.row]

    guard let title = doseData.value(forKey: "posted_on") as? String else {
        fatalError("Couldn't find data with key: posted_on")
    }
    navigationController.title = title
}    

我放置fatalError只是为了调试。

通过获取可见单元格来更改页面标题

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    for cell in dosetable.visibleCells {
    let indexPath = dosetable.indexPath(for: cell)
    let doseData = doseArry[(indexPath?.row)!]
    let post_interests = doseData.value(forKey: "post_interests") as! [AnyObject]
    let bttnImgUrl = post_interests[0].value(forKey: "image") as? String
    let intrstTag = post_interests[0].value(forKey: "id") as! String
    let postIntrest = doseData.value(forKey: "post_interests") as! [AnyObject]
    bttnImg.kf.setImage(with: URL(string: bttnImgUrl!))
    intrestTitle.setTitle(postIntrest[0].value(forKey: "name") as? String, for: .normal)
    intrestTitle.addTarget(self, action: #selector(intrestBttn(sender:)), for: .touchUpInside)
    intrestTitle.tag = Int(intrstTag)!
    intrestBttn.tag = Int(intrstTag)!
    intrestBttn.addTarget(self, action: #selector(intrestBttn(sender:)), for: .touchUpInside)
    timeAgo.text = NSLocalizedString((doseData.value(forKey: "posted_on") as? String)!, comment: "")
    intrestBttn.setBackgroundImage(bttnImg.image, for: .normal)
    }
}

您应该向我们提供一些代码,或者至少是您拥有的以及您想要实现的内容的屏幕截图。您的问题目前还不清楚我试图在cellForRowAt Indexath方法中更改导航标题,但它无法正常工作,就像我想更改导航栏标题一样,当表格单元格结束滚动到下一个索引时,下一个索引数据将是导航栏标题当页面加载第一次索引从1开始时,当我向下滚动时,下一个索引数据将从0开始