[英]unrecognized selector with UILocalizedIndexedCollation.current().section(for:collationStringSelector:#selector(getter: UIPreviewAction.title))
[英]collationStringSelector error : Unrecognized selector
我試圖在我的應用程序中實現字母部分來學習Swift。 我找到了這個教程來幫助我: http : //www.pumpmybicep.com/2014/07/04/uitableview-sectioning-and-indexing/
首先,我將類與UITableViewController類分開以提高可讀性。
但我在collationStringCollector上有一個錯誤,它不識別“m_titre”,我不明白collationStringSelector是如何工作的,所以,如何使用它。
var lesCours: [Cours] = cours_array.map { eachCours in // cours_array contain all "Cours" which will be indexed
eachCours.section = self.collation.sectionForObject(eachCours, collationStringSelector: "title")
return eachCours
}
這是我的班級“Cours”
class Cours {
var m_id : String
var m_titre : String
var m_content : String
var m_accept : Bool
var m_date : NSDate?
var section: Int?
init(titre:String, content:String)
{
self.m_titre = titre
self.m_content = content
self.m_id = ""
self.m_accept = false
self.m_date = nil
}
// ... getters, setters, specifics function
謝謝
PS:如果我的英語不完美,我道歉,這不是我的母語,我希望你能毫無困難地理解,盡管如此
選擇器使用Objective-C消息傳遞,因此該屬性必須是“Objective-C兼容”。 實現此目的的最簡單方法是使您的類成為NSObject
的子類:
class Cours : NSObject {
// ...
}
當然,選擇器必須匹配屬性的名稱,在您的情況下為“m_titre”而不是“title”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.