gpt4 book ai didi

ios - 如何获取特定 UITableViewCell 上方(或下方)的 TableView Cell

转载 作者:行者123 更新时间:2023-11-30 14:17:21 25 4
gpt4 key购买 nike

谁能告诉我如何访问特定单元格上方(或下方)的 UITableViewCell?我可以访问用户使用 didSelectRowAtIndexPath 选择的单元格:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var currentCell = tableView.cellForRowAtIndexPath(indexPath) as UITableViewCell?
}

我知道如何访问单元格的行号:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var currentRowNum = indexPath.row
}

有没有办法访问上面或下面一行的单元格?

非常感谢所有帮助!

最佳答案

像这样。

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//Current cell...
var currentCell = tableView.cellForRowAtIndexPath(indexPath) as UITableViewCell?

//Next cell...
let nextIndex = NSIndexPath(forRow: indexPath.row + 1, inSection: indexPath.section)
var nextCell = tableView.cellForRowAtIndexPath(nextIndex) as UITableViewCell?

//Previous cell...
let prevIndex = NSIndexPath(forRow: indexPath.row - 1, inSection: indexPath.section)
var prevCell = tableView.cellForRowAtIndexPath(prevIndex) as UITableViewCell?
}

关于ios - 如何获取特定 UITableViewCell 上方(或下方)的 TableView Cell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30962741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com