简体   繁体   English

IOS-意外崩溃,没有崩溃信息

[英]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. 我一直在多个平台上测试IOS应用程序,并且在iPhone 4S上进行测试时观察到一些奇怪的行为。 The app crashes after performing a task that works on both the iPhone 5 and iPhone 3S. 在执行适用于iPhone 5和iPhone 3S的任务后,该应用程序崩溃。 When the crash happens there is nothing displayed on the debugger, absolutely no crash log or memory warnings appear in Xcode. 当崩溃发生时,调试器上没有任何显示,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. 该代码是较大方法的一部分,该方法可下载大量图像并将其显示在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. 每个图像要分配给的UIImageViews的标记范围是100-104,因此可以使用循环索引变量对其进行访问。 The line UIImageView *imageHolder = (UIImageView *)[self.view viewWithTag:(100 + i)] extracts the UIImageViews from the main view. UIImageView *imageHolder = (UIImageView *)[self.view viewWithTag:(100 + i)]从主视图中提取UIImageViews。 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. 在下一行中,为imageHolder视图分配了一个图像,这是导致崩溃的行,并且在注释掉该视图时,该加载不会失败。 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. 我无法确定为什么会发生这种情况,或者无法正确设置imageFile或imageHolder视图。 Perhaps someone here can shed some light on the problem. 也许这里有人可以阐明这个问题。

You should have some protection around imageFile.getData as it could return nil . 您应该对imageFile.getData有所保护,因为它可能返回nil You should preferable use the getData: method which returns an error that you can use if the data can't be accessed. 您最好使用getData:方法,该方法返回一个错误,如果无法访问数据,则可以使用该错误。


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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM