gpt4 book ai didi

ios - Swift(一些)UITableViewDelegate 方法不执行

转载 作者:可可西里 更新时间:2023-11-01 00:18:18 25 4
gpt4 key购买 nike

我正在将我的一些代码从 ObjC 转换到 Swift。到目前为止一切顺利,但我遇到了一些未调用 UITableView 的委托(delegate)方法的问题。在 ObjC 中,我使用 tableView willDisplayCell forRowAtIndexPath 方法让我的单元格动画化到 View 中。虽然在 Swift 中向我建议了该方法,但它从未被调用过。 tableView willDisplayHeaderView forSectiontableView editActionsForRowAtIndexPath 也是如此。

我相当确定我的类(class)设置正确:

class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource

并且我的函数声明是被建议的,所以这些不可能是不正确的。

func tableView(tableView: UITableView!, editActionsForRowAtIndexPath indexPath: NSIndexPath!) -> [AnyObject]! {
...
}

func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) {
...
}

etc.

但是,虽然 tableView 数据显示得很好,但这些单独的委托(delegate)方法似乎从未运行过。这是一个错误,还是我遗漏了什么?谢谢!

最佳答案

你有没有告诉你的 TableView 委托(delegate)和数据源?

self.tableView.delegate = self;
self.tableView.datasource = self;

关于ios - Swift(一些)UITableViewDelegate 方法不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24842808/

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