ここに数行のコードがあります... currentPage は NSInteger で、imageViewHolder は NSMutableArray です。
NSLog(@"currentPage: %d, imageViewHolderCount: %d", currentPage, [imageViewHolder count]);
if(currentPage < [imageViewHolder count] - 1)
{
NSLog(@"%d < %d - 1", currentPage, [imageViewHolder count]);
tempView = [imageViewHolder objectAtIndex:currentPage + 1];
NSLog(@"doesn't get here, crashed."); //this doesn't get logged because of crash.
//do other stuff here
}
インデックスが範囲外であるため、「tempView = ...」行でクラッシュしています。これは私が得ている出力です:
currentPage: 0, imageViewHolderCount: 0
0 < 0 - 1
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
*** First throw call stack:
(0x339bd88f 0x324af259 0x339069db 0x48f1b 0x48c1b 0x35603a85 0x35603409 0x35602c57 0x35716b0f 0x3560424d 0x4abfb 0x324ab175 0x43f77 0x45b91 0x479a7 0x36bff 0x285ed 0x35604ecb 0x32935933 0x33991a33 0x33991699 0x3399026f 0x339134a5 0x3391336d 0x32e91439 0x35608e7d 0xfa01 0xf9c0)
明らかな何かが欠けていると確信しています... ifステートメントがtrueと評価されるのはなぜですか? 0が実際には-1より大きいことはかなり確信しています:)