2017-07-09 12 views
0

連絡先やApple Musicのスクロールバーのようなアルファベット順のスクロールバーを作成しようとしています。ただし、sectionIndexTitlesForTableViewメソッドを呼び出すと、アルファベットのスクロールバーが表示されません。これをどうやって解決するのですか?私はこれをolder tutorialnewer tutorialと言いました。アルファベット順のスクロールバーが表示されない

コード

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)! 
    } 
} 

答えて

1

あなたのチュートリアルでは、スウィフトの以前のバージョンのためのものです。現在の関数シグネチャは、

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

func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { 
    return sectionTitles.index(of: title)! 
} 
です。
関連する問題