我是一個計數plist文件中的值的問題,問題是if語句應該檢查值是否大於我的plist中的對象,然後停止移動到下一頁,這裏是我的代碼,但:問題與[陣列計數]
picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"images" ofType:@"plist"]];
arrays = [picturesDictionary objectForKey:@"PhotosArray"];
int photoCount = [arrays count];
if ((photoNumber < 1) || (photoNumber > photoCount)) return nil;
controller = [BookController rotatableViewController];
PhotosInAlbum.image = [UIImage imageNamed:[arrays objectAtIndex:pageNumber]];
但當照片到達最後一頁後,應用程序會崩潰,調試消息:
'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (30) beyond bounds (30)'
*** First throw call stack:
'[NSArray count]'給出了數組中項目的數量,而不是最後一項的索引。 – Manuel