I have a completely custom view that holds a UITableView and a Custom Tab Bar (basically a UIView that contains 6 UIButtons).
I am loading data from a plist file, and then I am sorting the data into multiple arrays based on categories (an array for misc items, and array for mail items, etc.)
Each button in the tab bar represents a category, and when I press the button I call the custom function "miscSelected" and so on.
How can I have the table view completely reload and then display the tableview based on the array selected (select the misc category and the tableview clears itself and loads the misc array data, same for any other category)?
The method I have experimented with is created and NSString named "selection" and then in each button function I set selected to equal whatever section I am selecting. In my cellForRoxAtIndexPath method I have this:
if ([self.selection isEqualToString:@"All Items"]) {
NSArray *mainDataArray = [NSArray arrayWithContentsOfFile:self.plistFile];
NSSortDescriptor *brandDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:brandDescriptor];
self.sortedData = [mainDataArray sortedArrayUsingDescriptors:sortDescriptors];
}
else if ([self.selection isEqualToString:@"Misc Items"]){
self.sortedData = [NSArray arrayWithContentsOfFile:self.plistFile];
}
cell.itemTitle.text = [[self.sortedData objectAtIndex:indexPath.row] objectForKey:@"name"];
For the sake of example and testing I am simply displaying the same data, just one button displays it in alphabetical order and the other does not.
This code works only when I start to scroll down and back up, but it does not actually update on button press. Calling myTable reloadData does not do anything either.
Any help would be great, thanks!