I have a UITableView displaying a list of plants in alphabetical sections. Within the app, the user can change the language. When the language is changed, the method:

[self.tableview reloadData];

now displays the same plants in a new language. The problem is that the rows and sections are intact, and still sorted in the alphabetical order of the previous language. I have googled and read up and down stackoverflow to find a solution. The closest I came was:

[[self tableView]reloadData];
NSRange range = NSMakeRange(0, [self numberOfSectionsInTableView:self.tableView]);
NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];

Still, I have to run the tableView through viewdDidLoad to change the alphabetical sorting.

What is the best way to force a new alphabetial sorting after [[self tableview]reloadData]; ?

有帮助吗?

解决方案

Before calling reloadData you first need to update all of your data used by the table view data source and delegate methods.

You do not need to call viewDidLoad again. Put the code to setup the data structures in its own method. Then you can call this setup method from viewDidLoad (if needed) as well as just before calling reloadData after a language change.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top