1

I have a UITableViewController containing some very basic data. Assume each row just contains a random integer. I'd like to sort these rows (either ascending or descending is fine). I have a "Sort" button and a "sortItems" delegate that's called when the Sort button is tapped. How do I sort the contents of the UITableViewController and update the display? I also store the data displayed in the UITableViewController in an array if that helps.

Cheers!

2
  • can you post the code for your cellForRowAtIndexPath? Commented May 20, 2011 at 16:27
  • Thanks for the responses! I just didn't know about the reloadData method. Commented May 20, 2011 at 18:00

2 Answers 2

2

The data source associated to your UITableViewController is the main access point to the data you display in your cell.

How don't know how your data model looks like, but it could be as simple a matter as sorting an array of integer (in your example) store in your data source.

When I say "data source" I mean: the object that is implementing the UITableViewDataSource Protocol

So, sort your model and then reloadData in your tableViewController.tableView.

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming you have integers saved in an array, sort it, and then use it to fill the tableview by customizing

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 

to populate cell i with sortedInts[i].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.