2017-07-09 3 views
0

Ich versuche, eine alphabetische Bildlaufleiste wie die Bildlaufleiste in den Kontakten und in Apple Music zu erstellen. Wenn ich jedoch sectionIndexTitlesForTableView Methode aufrufen, wird die alphabetische Bildlaufleiste nicht angezeigt. Wie behebe ich das? Ich habe diese older tutorial und newer tutorial verwiesen.Alphabetische Bildlaufleiste wird nicht angezeigt

-Code

class SongsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 
    private var sectionTitles = ["A", "B", "C"] 

    func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]! { 
     return sectionTitles as [AnyObject] 
    } 

    func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { 
     return sectionTitles.index(of: title)! 
    } 
} 

Antwort

1

Ihre Tutorials sind für frühere Versionen von Swift. Die aktuellen Funktionssignaturen sind:

func sectionIndexTitles(for tableView: UITableView) -> [String]? { 
    return sectionTitles 
} 

func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { 
    return sectionTitles.index(of: title)! 
} 
Verwandte Themen