【发布时间】:2017-01-23 23:42:04
【问题描述】:
我对 Swift 3 函数调用有一些疑问。下面是一个例子。
老斯威夫特:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell
斯威夫特 3:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
上面的语法很好。但现在 Xcode 向我显示一个错误并要求我执行以下操作:
@objc(tableView:cellForRowAtIndexPath:) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
我不明白为什么我必须声明@objc(tableView:cellForRowAtIndexPath:)。
仅当我尝试在扩展下实现表视图数据源方法时才会发生这种情况。 numberOfRowsInSection 或 viewForHeaderInSection 也不会发生这种情况。
谁能帮我理解为什么会这样?
【问题讨论】:
标签: ios uitableview swift3