开发者

Sorting rows in UITableViewController

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 UITableVie开发者_如何学CwController in an array if that helps.

Cheers!


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.


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].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜