我想要做一個程序,其中有一個product
,我希望將其移入storehouse
。Objective C - 數組中的數量總是重置爲零,但爲什麼?
實施例:
移動從庫存(手邊)蘋果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個移動從蘋果庫存倉庫參考和數量似乎罰款。
但是,如果我刷新/重新加載頁面,庫存中的qty被重置爲零,即使這裏有一個項目。
我不知道是什麼導致倉庫物品的數量被設置爲零。
這是一個日誌輸出;
// 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
我會去複製,我以前沒有做過;我不想複製(通過編寫代碼)每個屬性,因爲它們中有很多。 – zardon 2013-02-16 16:10:40
我認爲你是對的,我使用nscopy做了一個基本的測試,並且我能夠確保數量至少在工作,儘管我只是測試了一下它,因爲我對nscopy非常陌生。 – zardon 2013-02-16 19:14:02