Swift:转换此 Objective C 方法
Swift: Converting this Objective C Method
对 iOS 很陌生,不太确定我在这里做错了什么......
我正在按照 this tutorial 构建一个手风琴风格的 UITableView,作者似乎已经实现了一个扩展 UITableViewController
的委托函数。本教程不符合任何委托,因此我只能假设您能够直接编写扩展。
原代码为:
- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section
{
if (section>0) return YES;
return NO;
}
分析完后,我在 Swift 中构建了以下内容:
func tableView(tableView: UITableView, canCollapseSection section: Int) -> Bool {
if section > 0 {
return true
}
return false
}
我知道它是一个非常简单的函数,但我想让这个函数作为所提供的基本 TableView 函数的扩展来工作。目前XCode在我调用它时无法识别此函数
self.tableView.canCollapseSection(tableView, indexPath.section)
你可以这样称呼它
self.tableView(tableView, canCollapseSection: indexPath.section)
对 iOS 很陌生,不太确定我在这里做错了什么......
我正在按照 this tutorial 构建一个手风琴风格的 UITableView,作者似乎已经实现了一个扩展 UITableViewController
的委托函数。本教程不符合任何委托,因此我只能假设您能够直接编写扩展。
原代码为:
- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section
{
if (section>0) return YES;
return NO;
}
分析完后,我在 Swift 中构建了以下内容:
func tableView(tableView: UITableView, canCollapseSection section: Int) -> Bool {
if section > 0 {
return true
}
return false
}
我知道它是一个非常简单的函数,但我想让这个函数作为所提供的基本 TableView 函数的扩展来工作。目前XCode在我调用它时无法识别此函数
self.tableView.canCollapseSection(tableView, indexPath.section)
你可以这样称呼它
self.tableView(tableView, canCollapseSection: indexPath.section)