Question

I have seen numerous examples for how to use a custom cell in a UiTableView to list data in columns. What I want to know is, what is a good way to interact with this kind of table so that the user can choose a column for sorting?

For example, say there are three columns, a, b, and c. By default, the data are displayed with the contents sort so that column a is ascending. If the user {does something} then the table re-sorts and displays the data sorted with either column b or column c ascending, etc.

Note that I am not asking how to sort my data, create a data structure, or format the table once I know which column to sort with. I am only asking what is the best user interaction for indicating to sort with column x?

Was it helpful?

Solution

Asking for the "best" way to do something is pretty subjective. There are a bunch of things you could do, depending on what look you want. If you only have one section, you could use a section header with a segmented control, or three buttons, one over each "column" to perform the sorting. If you want to do it by tapping on the "cell", you could make the cells be UIButtons, to which you can add an action method that does the sorting. You can identify which "column" is tapped by giving the buttons IBOutlets, or by using tags.

OTHER TIPS

I think the simplest way to achieve it is:

  1. Store you data (a, b, c, ...) in separate array;
  2. Add UISegmentedControl with your sort types;
  3. [yourTableView reloadData] after sorting data array in segment changes handler.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top