[数组计数]问题

Mc.*_*ver 0 cocoa-touch objective-c ios

我是在一个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]];
Run Code Online (Sandbox Code Playgroud)

但是当照片到达最后一页时,应用程序将崩溃,调试器消息:

'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (30) beyond bounds (30)'
*** First throw call stack:
Run Code Online (Sandbox Code Playgroud)

Vik*_*ica 5

尝试 __CODE__

它崩溃的原因是,该计数将给出对象的数量,但是当访问每个对象时,你从0开始,所以[数组计数] -1是最后一个索引.