ScottOBot
ScottOBot

Reputation: 849

IOS - Unexpected Crash With No Crash Info

I have been testing an IOS app on multiple platforms and have observed some weird behaviours while testing on the iPhone 4S. The app crashes after performing a task that works on both the iPhone 5 and iPhone 3S. When the crash happens there is nothing displayed on the debugger, absolutely no crash log or memory warnings appear in Xcode. I isolated the block of code, and the specific line responsible for the crash. I still don't understand why it is happening or how to find a solution. The code is part of a larger method that downloads a number of images and displays them in UIImageViews. Here is the code:

//fill image tiles with images
for (int i = 0; i < [objects count]; ++i)
{
    PFObject *imageObject = [objects objectAtIndex:i];
    PFFile *imageFile = (PFFile *)[imageObject objectForKey:@"image"];
    UIImageView *imageHolder = (UIImageView *)[self.view viewWithTag:(100 + i)];

    imageHolder.image = [UIImage imageWithData:imageFile.getData];
}

The code loops through an object that has been loaded with image files from a server. The UIImageViews that each image is meant to be assigned to are tagged from 100 - 104, so they can be accessed with the loop index variable. The line UIImageView *imageHolder = (UIImageView *)[self.view viewWithTag:(100 + i)] extracts the UIImageViews from the main view. In the next line the imageHolder view is assigned an image, this is the line that causes the crash, and when commented out the view loads without fail. I haven't been able to determine why this is happening or if it is the imageFile or imageHolder view that is not being set up properly. Perhaps someone here can shed some light on the problem.

Upvotes: 0

Views: 154

Answers (1)

Wain
Wain

Reputation: 119041

You should have some protection around imageFile.getData as it could return nil. You should preferable use the getData: method which returns an error that you can use if the data can't be accessed.


NSError *error = nil;
NSData *imageData = [imageFile getData:&error];

if (imageData != nil) {
    imageHolder.image = [UIImage imageWithData:imageData];
} else {
    NSLog(@"OMG!! %@", error);
}

Upvotes: 1

Related Questions