嗨,我有一点问题。我做了一个从 xml 读取并显示图像的应用程序。该应用程序在模拟器上运行良好,但有时该应用程序确实在 iphone 4 上崩溃。它可能是什么?我的治疗有问题还是其他地方有问题?代码如下。谢谢你
-(void)waiting{
// replace right bar button 'refresh' with spinner
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(self.view.bounds.size.width/2, (self.view.bounds.size.height/2)-50);
spinner.hidesWhenStopped = YES;
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:spinner];
[spinner startAnimating];
// how we stop refresh from freezing the main UI thread
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
// do our long running process here
[NSThread sleepForTimeInterval:0.2];
// do any UI stuff on the main UI thread
dispatch_async(dispatch_get_main_queue(), ^{
[self start];
[self picture];
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(animate) userInfo:nil repeats:YES];
[spinner stopAnimating];
});
});
dispatch_release(downloadQueue);
}
-(void)start{
xmlElementObjects = [[NSMutableArray alloc] init];
parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.i-store.si/Storage/Images/app/galerija.xml"]];
[parser setDelegate:self];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if(![elementName compare:@"PictureInfo"])
{
array = [[NSMutableArray alloc] init];
}
else if(![elementName compare:@"imageURL"])
{
currentAttribute = [NSMutableString string];
}
else if(![elementName compare:@"imageTitle"])
{
currentAttribute = [NSMutableString string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(![elementName compare:@"PictureInfo"])
{
}
else if(![elementName compare:@"imageURL"])
{
[array addObject:currentAttribute];
pictures=pictures+1;
currentAttribute = nil;
}
else if(![elementName compare:@"imageTitle"])
{
}
else if(![elementName compare:@"Pictures"])
{
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(self.currentAttribute)
{
[self.currentAttribute appendString:string];
}
}
更新:我尝试了 Bugsense,这就是我得到的:
CLASS:
SIGNAL
FILE:
_mh_execute_header +
0libobjc.A.dylib 0x31946fbc objc_msgSend + 15
1Foundation 0x31da161d __NSFireTimer + 144
2CoreFoundation 0x37e3aa63 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
3CoreFoundation 0x37e3a6c9 __CFRunLoopDoTimer + 364
4CoreFoundation 0x37e3929f __CFRunLoopRun + 1206
5CoreFoundation 0x37dbc4dd CFRunLoopRunSpecific + 300
6CoreFoundation 0x37dbc3a5 CFRunLoopRunInMode + 104
7GraphicsServices 0x3793afcd GSEventRunModal + 156
8UIKit 0x3524c743 UIApplicationMain + 1090
9My_app 0x0000273b _mh_execute_header + 5947