开发者

Can I add an alphabet jump list to a tableview like the contact list

I would like t开发者_如何转开发o create a custom contact list in my app offering a similar A-Z jump list like the standard contact list does.

Is this possible with a TableView?


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


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
}


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.


Have a look at the UITableViewDataSource documentation. There's a method sectionIndexTitlesForTableView: and tableView:sectionForSectionIndexTitle:atIndex:. These should get you going.


Yes. Implement the -sectionIndexTitlesForTableView: method in the data source.

See the TableViewSuite example code for how to use it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜