0

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?

Brandon
  • 19
  • 5
  • I could see my way to a solution if there was a way of identifying which cell has been tapped...but since the "cell" is a sub component of the row, this seems nontrivial. Any takers? – Brandon Jul 02 '13 at 02:00

2 Answers2

0

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • I did not think of using a section header or a different custom cell. I think one of these will work well in my app. Thanks! – Brandon Jul 02 '13 at 03:28
0

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.
Valentin Shamardin
  • 3,569
  • 4
  • 34
  • 51