簡體   English   中英

Swift:轉換此Objective C方法

[英]Swift: Converting this Objective C Method

iOS的新手,不太確定我在這里做錯了什么...我正在按照本教程構建手風琴風格的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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM