EDIT: I stuck in a single call to manually retain the array right after initializing it, and that fixed it. Dur. Thanks.
I keep an NSMutableArray in a UIScrollView subclass, and I add to it instances of a UIImageView subclass as each is added as a subview. It needs to be a mutable array, as I plan to rearrange their order in the array eventually; this bug is occurring before I even try to do so. I've used NSLogs to show that the array has count 10 up until and including applicationDidBecomeActive: is called in my AppDelegate, and added a timer to fire every 0.001s in the run loop. The first time it fires, it can't find the array anymore! I'm very confused and have been trying to track this down for hours.
The timer's working properly (i.e. when printCount: doesn't access the array, it's fine), it's only when I try to access the array there that it breaks. The regular call to printCount: below works, but the first time the timer fires I What could possibly be happening between these two calls to printCount:?
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSTimer *timer = [[NSTimer scheduledTimerWithTimeInterval:0.001f
target:[viewController view]
selector:@selector(printCount)
userInfo:nil
repeats:YES]
retain];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[[viewController view] printCount];
}
I've been endlessly stepping through the program with the debugger. The array is correct right up through this point, and its memory address is the same even after its contents are changed. However, there is only object in it afterwards -- its 10 elements get replaced by a single UITouchData instance. No idea where it comes from. None of my event-handling methods attempt to reassign the array or change it. Any ideas what could be going wrong? I'm completely mystified.