Can I add an alphabet jump list to a tableview like the contact list
Absolutely, just return an array of NSStrings
from the UITableViewDataSource
method -sectionIndexTitlesForTableView
For the record, this "jump list" is called a section index.
You also need to correspond this with the actual amount of sections that you have, if not, then you can use tableView:sectionForSectionIndexTitle:
to play around with which sections get shown for which indexes.
The docs, my friend, read the docs.
Swift 4.0 and 5.0 Just implement the following methods and return the list.
var list = ["A","B","C","D"];
override func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return list
}
There is a comprehensive tutorial on how to do it in the "Table View Programming Guide", called "Populating an Indexed List".
Moreover, if you also need to have the search functionality (the magnify icon), there are two well written solutions:
- http://iamthewalr.us/blog/2009/12/uisearchdisplaycontroller-and-uilocalizedindexedcollation/
- http://lukeredpath.co.uk/blog/using-uilocalizedindexedcollation-with-searchable-table-views.html