问题
I am experiencing problems using ASIHttpRequst. This is the error I get:
2010-04-11 20:47:08.176 citybikesPlus[5885:207] *** -[CALayer rackDone:]: unrecognized selector sent to instance 0x464a890
2010-04-11 20:47:08.176 citybikesPlus[5885:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[CALayer rackDone:]: unrecognized selector sent to instance 0x464a890'
2010-04-11 20:47:08.176 citybikesPlus[5885:207] Stack: (
33936475,
2546353417,
34318395,
33887862,
33740482,
126399,
445238,
33720545,
33717320,
40085013,
40085210,
3108783,
11168,
11022
)
And this is my code (Part of it):
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[image setImage:[UIImage imageNamed:@"bullet_rack.png"]];
BikeAnnotation *bike = [[annotationView annotation] retain];
bike._sub = @"";
[super viewDidLoad];
NSString *newUrl = [[NSString alloc] initWithFormat:rackUrl, bike._id];
NSString *fetchUrl = [newUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[networkQueue cancelAllOperations];
[networkQueue setRequestDidFinishSelector:@selector(rackDone:)];
[networkQueue setRequestDidFailSelector:@selector(processFailed:)];
[networkQueue setDelegate:self];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:fetchUrl]] retain];
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
[networkQueue addOperation:request];
[networkQueue go];
}
- (void)rackDone:(ASIHTTPRequest *)request
{
NSString *resultSearch = [request responseString];
NSData *data = [resultSearch dataUsingEncoding:NSUTF8StringEncoding];
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSDictionary * dict = (NSDictionary*)[NSPropertyListSerialization
propertyListFromData:data
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
rackXmlResult* fileResult = [[[rackXmlResult alloc] initWithDictionary:dict] autorelease];
rackXmlSet *rackSet = [fileResult getRackResult];
NSString *subString = [[NSString alloc] initWithFormat:@"Cyklar tillgängligt: %@ -- Lediga platser: %@", rackSet._ready_bikes, rackSet._empty_locks];
[activity setHidden:YES];
[image setHidden:NO];
BikeAnnotation *bike = [annotationView annotation];
bike._sub = subString;
}
- (void) processFailed:(ASIHTTPRequest *)request
{
UIAlertView *errorView;
NSError *error = [request error];
NSString *errorString = [error localizedDescription];
errorView = [[UIAlertView alloc]
initWithTitle: NSLocalizedString(@"Network error", @"Network error")
message: errorString
delegate: self
cancelButtonTitle: NSLocalizedString(@"Close", @"Network error") otherButtonTitles: nil];
[errorView show];
[errorView autorelease];
}
The process is loaded as LeftCalloutView in the callout bubble when annotations are loaded in my mapview, so quite a lot (80 times or so). It is meant to retrieve a XML Plist from a server, parse it and use the data... but it dies at the rackDone:
Does anybody have any ideas?
Regards, Paul Peelen
回答1:
Well, the problem appears to be that your networkQueue
object (whatever that is NSOperationsQueue subclass?) is sending the rackDone:
message to the viewController's view instead of the viewController itself. CALayers are attributes of views not viewControllers so the error has to be coming from a view.
Check the code for networkQueue
.
You also don't seem to be using the self
notation for networkQueue
and if its a property of the class it may die without warning because it is not properly retained.
回答2:
I found the solution using [self retain]
. It seems that because I load the object so often, it doesn't allocate it self long enough to receive the rackDone: action.
It works now. Now I just need to figure out how I can load this on request, not when the app is loaded.
来源:https://stackoverflow.com/questions/2618300/asihttprequest-problems-unrecognized-selector-sent-to-instance