product
に移動したいプログラムを実行しようとしていstorehouse
ます。
例:
25箱のリンゴを在庫(手持ち)から倉庫に移動します。
商品を倉庫に追加しlistOfProducts
て在庫をゼロにすると、あるべきではないのに、何らかの理由で倉庫の商品にも影響が出ます。
プロセスは次のようになります。
- 倉庫に移動したい製品オブジェクトを見つけます
- 倉庫の数量を更新し、数量が手持ちの在庫を追加していることを確認します
- 倉庫のlistOfProductsに商品オブジェクトを追加します
- 在庫在庫をゼロにする(0)
しかし、それは倉庫を数量0にするのですか?なんで?これを行うべき理由はないようです。
これは意図されたものではありませんが、参照しているオブジェクト間にシンボリックリンクを強制したようです。
最初にオブジェクトのコピーを作成する必要がありますか?
いくつかのメモ。
a。倉庫はオブジェクトであり、各都市には倉庫があります(つまり、city.listOfStorehouses)。
b。city.listOfStorehousesはシングルトンに保持されるため、状態を保存したり、ページ間で状態を渡したりすることは問題ありません。
c。アイテムは倉庫に追加されますが、数量はゼロにリセットされますか?しかし、なぜ?
// Try to move X goods from inventory -> storehouse
NSLog(@"Goods to move = %@, %d crates", self.product.name, self.crates);
// I add the qty to the product I want to put into the storehouse
self.product.qty += self.crates;
// Append the array (I should check if the product already exists but this does not matter right now)
[self.storehouse.listOfProducts addObject:self.product];
// Reset crates because it should always be zero because you've moved them
// from your inventory into a storehouse
self.crates = 0;
さて、在庫ページで25個のリンゴを在庫から倉庫に移動すると、参照と数量は問題ないように見えます。
ただし、ページを更新/再読み込みすると、アイテムがあったとしても、倉庫の数量はゼロにリセットされます。
倉庫のアイテム数量がゼロに設定されている原因がわかりません。
これがログ出力です。
// Log output
// Stock page
// Goods to move = Apples, 25 crates, seems to be storing fine, no problem.
2013-02-16 09:40:27.257 TestApp[1524:c07] Storehouse = (25/500)
2013-02-16 09:40:27.260 TestApp[1524:c07] #0 storehouse item = Apples with 25 crates
// Previous page
// When I go back to the previous page, the qty is zero?? WHY?
2013-02-16 09:41:33.980 TestApp[1524:c07] Storehouse = (0/500)
2013-02-16 09:41:33.980 TestApp[1524:c07] #0 storehouse item = Apple with 0 crates