I have an NSMUtable array of images where a different image is displayed with a previous and a next button, but when I get to the end of the array the simulator crashes. I want to loop the end of the array to the beginning so that when I get to the end of the array of images when I hit the next button again it loops back to the first image, also when Im at the first image if I hit the previous button it loops to the last image with no crashes
Share
What you want is a circular array, which is easy to implement using a standard
NSMutableArray. For instance, say you store your images in an array calledimageArrayand use a simple variable to keep track of the index of your current image, like:…then you might implement
nextImageandpreviousImagelike:Then just use
nextImageandpreviousImagewhenever you want to step through the array, and problem solved.