Customize the index view of a UITableView. This allows users to scroll with more precision than the standard controls Apple offers.
Using Apple's standard control | Using M4KTableIndexView |
---|---|
Open and run the included SampleContactList.xcodeproj
- Copy the files from M4KTableIndexView/ into Xcode.
- In your View Controller, add an IBOutlet for the View:
@IBOutlet weak var indexView: M4KTableIndexView!
- Setup the indexView:
indexView.tableView = self.tableView
indexView.indexes = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
indexView.setup()
- Add a UIView element to your Storyboard positioned next to your UITableView. Connect this to the IBOutlet created in #2.
- (Optional) Make your View Controller be the indexView's delegate and implement the delegate method:
class ViewController: UIViewController, M4KTableIndexDelegate {
...
indexView.delegate = self
...
func indexDisplayText(for indexPath: IndexPath) -> String {
// Return a short string to display on screen
return ""
}