0

The else part of this works fine. But if itemFlag is true, I can't get the new information to display itself correctly after doing the alphabetic sort. Quitting the programme and restarting shows the new item to have been added successfully to the array, and everything is diplayed correctly.

So my question is, why is reloadData not working if itemFlag is true?

Here is the code:

- (void)changeFoodDetails:(NSString *)foodName withPoints:(NSString *)foodPoints{
    if (newItemFlag) {

        [_foodStuffsArray insertObject:[[FoodItem alloc] initWithName:foodName points:[foodPoints intValue]] atIndex:0];

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

        [sharedManager sortFoodStuffArrayByName];
        [self.tableView reloadData];

        newItemFlag = false;
    }else {
        [_foodStuffsArray removeObjectAtIndex:currentFoodstuffArrayEntry];
        [_foodStuffsArray insertObject:[[FoodItem alloc] initWithName:foodName points:[foodPoints intValue]] atIndex:currentFoodstuffArrayEntry];
        [self.tableView reloadData];
    }
}
Prasad G
  • 6,702
  • 7
  • 42
  • 65
haarlequin
  • 23
  • 3

0 Answers0