0

これの他の部分は正常に機能します。しかし、itemFlagがtrueの場合、アルファベット順の並べ替えを行った後、新しい情報を取得して正しく表示することはできません。プログラムを終了して再起動すると、新しいアイテムがアレイに正常に追加され、すべてが正しく表示されます。

だから私の質問は、itemFlagがtrueの場合にreloadDataが機能しないのはなぜですか?

コードは次のとおりです。

- (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];
    }
}
4

0 に答える 0