0
我遇到了一個大問題NSInvocationOperation
。當我在我的iPod 4上運行固件5.0.1時,沒關係。但在我的iPhone 4,iOS 4.1上,它墜毀了。這是我的代碼:訪問崩潰的NSInvocationOperation
CustomAnnotation *annotation = [[[ModelManager defaultModelManager] getAnnotationDictionaryInMemory] objectForKey:joltId];
if (annotation == nil)
annotation = [[[ModelManager defaultModelManager] getAnnotationDictionaryInMemory] annotationWithInstagramId:eID];
if (annotation == nil)
continue;
//THIS ONE CRASH ON IPHONE 4 OS 4.1
NSDictionary *param = [[NSDictionary alloc] initWithObjectsAndKeys: @"aKey", @"aValue", nil];
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:annotation selector:@selector(updateAnnotation:) object:param];
[_queue addOperation:op];
[op autorelease];
updateAnnotation函數,CustomAnnotation類中定義:
- (void)updateAnnotation:(id)sender {
//NSLog(@"UPDATE ANNOTATION ID: %@", self.annoID);
NSDictionary *senderDic = (NSDictionary *)sender;
UzooltAppDelegate* appDelegate = (UzooltAppDelegate*) [UIApplication sharedApplication].delegate;
if ([senderDic objectForKey:@"nb_rejolt"] != nil) {
NSInteger new_nb_rejolts = [[senderDic objectForKey:@"nb_rejolt"] intValue];
//if (new_nb_rejolts != rejolts) {
//NSLog(@"update nb rejolts: %d", new_nb_rejolts);
if (self.rejolts != new_nb_rejolts) {
self.rejolts = new_nb_rejolts;
//if (self.isGrouped)
// [self.masterAnnotation.annotationView performSelectorOnMainThread:@selector(updateAnnotationViewWithRejolts:) withObject:[NSString stringWithFormat:@"%d", rejolts] waitUntilDone:NO];
//else
if ([senderDic objectForKey:@"rejolt_fbid"] != nil) {
NSString *fbRejoltsString = [senderDic objectForKey:@"rejolt_fbid"];
self.fbRejolts = [[fbRejoltsString componentsSeparatedByString:@","] mutableCopy];
[self.fbRejolts removeLastObject];
[self updateNumberOfRejoltsFromFBFrds];
}
[self.annotationView performSelectorOnMainThread:@selector(updateAnnotationViewWithRejolts:) withObject:[NSString stringWithFormat:@"%d", rejolts] waitUntilDone:NO];
}
if (self.isGrouped) {
if (self.masterAnnotation.isShowingRadius == NO && appDelegate.uMainViewController.isInGroup == NO && (new_nb_rejolts > self.masterAnnotation.rejolts || (new_nb_rejolts == self.masterAnnotation.rejolts && self.getAge < self.masterAnnotation.getAge))) {
[self.masterAnnotation removeFromGroupedAnnotations:self];
self.annotationView.hidden = NO;
[self.annotationView performSelectorOnMainThread:@selector(showWithAlpha:) withObject:[NSNumber numberWithFloat:annotationAlpha] waitUntilDone:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:@"need_group_annotations" object:nil];
}
}
//}
}
if ([senderDic objectForKey:@"lifetime"] != nil) {
float new_lifetime = [[senderDic objectForKey:@"lifetime"] floatValue]*3600;
//NSLog(@"new lifetime: %.f", new_lifetime);
if (new_lifetime != lifetime) {
//NSLog(@"update lifetime");
self.lifetime = new_lifetime;
}
}
[self updateViewAlpha];
if ([senderDic objectForKey:@"radius"] != nil) {
float new_radius = [[senderDic objectForKey:@"radius"] floatValue];
if (new_radius != radius) {
//NSLog(@"update lifetime");
self.radius = new_radius;
}
}
/*
if ([appDelegate.uMainViewController isMaximumZoomIn])
[[self annotationView] performSelectorOnMainThread:@selector(setGroupNumberIndicatorVisible:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:NO];
else
[[self annotationView] performSelectorOnMainThread:@selector(setGroupNumberIndicatorVisible:) withObject:[NSNumber numberWithBool:NO] waitUntilDone:NO];
*/
if (isSelected == YES && isShowingRadius == NO) {
//NSLog(@"update details");
[self performSelectorOnMainThread:@selector(updateDetailsView) withObject:nil waitUntilDone:NO];
UzooltAppDelegate* appDelegate = (UzooltAppDelegate*) [UIApplication sharedApplication].delegate;
if (isGrouped == YES && appDelegate.uMainViewController.isInGroup) {
NSLog(@"grouped jolt rejolted");
[self performSelectorOnMainThread:@selector(updateInGroupAnnotationView) withObject:nil waitUntilDone:NO];
}
}
}
我不知道哪裏錯了?請幫幫我。謝謝大家!
我試圖接通NSZombies但它只能顯示線BAD ACCESS: NSInvocationOperation * OP = [[NSInvocationOperation的alloc] initWithTarget:註釋選擇器:@selector(updateAnnotation :)對象:PARAM] ; 不要告訴我什麼已經釋放。 – 2012-07-11 02:45:14
定義updateAnnotation方法在哪裏? – jjathman 2012-07-11 03:00:25
它在CustomAnnotation類中定義。 – 2012-07-11 03:52:49