0

I am wondering if there would be anybody here that could tell me how to successfully code UISegmented control so that the table view cells in my program can also be organised via the names along with the corresponding number (sorry for no picture)

I have already tried searching for a solution, but they are either complicated or not related at all. I obviously have to put this in my UITableView controller, and have to make an action and a property for the segmented control, but really wanted to know how i can reset a table view in a different order. Something simple would be great. Thanks

1 Answers1

1

You have to first register event for valueChanged like this:

A part from doc:

[segmentedControl addTarget:self
                     action:@selector(action:)
           forControlEvents:UIControlEventValueChanged];

Once it comes inside action selector, you have to check selectedSegmentIndex property and based on the index, re-arrange/re-order the datasource binded to the UITableView control as per the need.

For re-ordering you might use custom sorting.

Note: Once the source reordered don't forget to call [tableView reloadData] and set its delegate and datasource if it is not.

Community
  • 1
  • 1
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56