2016-03-29 18 views
0

Ich habe schon seit 2 Tagen über mein Problem gegoogelt. Aber ich konnte keine Lösung finden, die zu meinem Problem passt. Mein Problem ist, ich möchte eine benutzerdefinierte SectionIndexTitle für UITableView wie ein Bild unten machen. Bitte empfehlen Sie mir eine Bibliothek oder ein Konzept, um es zu tun. Vielen Dank. enter image description hereUITableView SectionIndexTitle Benutzerdefinierte Ansicht

Antwort

0

Wenn Sie versuchen, einen alphabetischen Index zu erstellen, gibt es eine Methode in UITableViewDelegate, die diese sofort unterstützt.

Sie müssen Ihre Abschnitte definieren und dann UIL-indexierte Sortierung verwenden, um sie zu indizieren.

let collation = UILocalizedIndexedCollation.currentCollation() 
    as UILocalizedIndexedCollation 

// table sections 
var sections: [Section] { 
    if self._sections != nil { 
     return self._sections! 
    } 

    // create objects from your datasource 
    var objects: [Object] = names.map { objectAttribute in 
     var object = Object(objectAttribute: objectAttribute) 
     object.section = self.collation.sectionForObject(object, collationStringSelector: objectAttribute) 
     return object 
    } 

    // create empty sections 
    var sections = [Section]() 
    for i in 0..<self.collation.sectionIndexTitles.count { 
     sections.append(Section()) 
    } 

override func sectionIndexTitlesForTableView(tableView: UITableView) 
    -> [AnyObject] { 
    return self.collation.sectionIndexTitles 
} 

override func tableView(tableView: UITableView, 
    sectionForSectionIndexTitle title: String, 
    atIndex index: Int) 
    -> Int { 
    return self.collation.sectionForSectionIndexTitleAtIndex(index) 
} 

Zum Lesen Sie mehr über UILocalized​Indexed​Collation

Verwandte Themen