我有一個變量值奇怪的問題。這是該代碼(這是一個類方法的一部分):iphone nslog損壞的數據
MyAppDelegate *pDelegate = [[UIApplication sharedApplication] delegate];
SomeDictionaryData *appData = [pDelegate.theData retain];
NSLog(@"my instance var: %@",cardIndex); // outputs "my instance var: 4"
NSDictionary *currentCard = [[NSDictionary alloc] initWithDictionary:[appData.cards objectAtIndex:cardIndex]];;
// the above line breaks the app
[currentCard release];
[appData release];
我使用與objc_exception_throw
斷點調試器。 objectAtIndex
在那裏收到的輸入顯示爲值= 13760640. appData的cards
屬性是NSArray
,它顯然沒有1000萬以上的項目,所以我得到了一個超出界限的錯誤。我試着用(int)cardIndex
鑄造沒有更好的結果。奇怪的是一些其他類中的類似代碼很好。
這是我想要在整個應用程序中使用的一些數據,所以我有一個Model類,它在AppDelegate中被初始化爲theData
,然後被不同的ViewController加以使用。在其他一些ViewController上成功訪問後,會出現此錯誤(該錯誤也會保留/釋放)。
任何幫助將不勝感激。
謝謝兄弟!雖然我得到一個「無效的接收器類型int」警告。 – mga 2009-08-25 02:44:27
嘗試投射爲(NSUInteger)並仍然收到警告。其他一切正常,但...我只是不喜歡警告。 – mga 2009-08-25 02:45:30
對!將所有必要的引用轉換爲NSNumber。謝謝! – mga 2009-08-25 03:45:14