I sort the UITableView as in this answer How to sort alphabetically a UITableView Sectioned?.
The problem is now that UITableView doesn’t push out the correct ViewControllers, due i have 2 localizations, English and Italian in my app. For english it works fine, but for italian not.
The code I’m using is this,as suggested in this answer Pushing View Controllers in UITableViewController Grouped:
if (indexPath.section == 0)
{
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:[[[FirstViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
case 1:
[self.navigationController pushViewController:[[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
break;
// and so on
}
}
Any ideas for this?
Your problem is totally logical and does not need a change in your code. When you sort the
tableViewarray, it is trivial thatdidSelectRowAtIndexPathwould get messed up while selecting rows.This might be because you would have implemented something like
If this is your case, then yes, when your sort the tableView you will push view controllers in a BAD WAY.
My suggestion is that you can take some properties in each row and check for that while pushing view controllers. For example, if you are… (say) having row 1 to be a certain letter or a number or a word, you can check for that and pushViewController accordingly.
But this will work only if you know all the elements in the
tableView(never mind sorting).You can check something like…
You can check for anything if you logically set and assign your properties in the
cellForRowAtIndexPathmethod and logically set it such that when you perform atableView reloadDataafter sorting, the flow of thedidSelectwould still be the same.Let us know if you still have problems.