2011-03-09 3 views
0

Vous avez essayé de créer une requête uniquement pour lancer une erreur d'exécution. Méthode à l'origine de la demande:Erreur d'exécution de lancement NSURLRequest

- (void)loadMemberData { 

    //build URL 
    NSMutableString *url = [[NSMutableString alloc] initWithString:appDelegate.apiURL]; 
    [url appendFormat:@"&subaction=singlestat&memberID=%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"memberID"]]; 

    NSURL *tempURL = [[NSURL alloc] initWithString:url]; 
    NSLog(@"URL: %@", tempURL); 

    //Create conn 
    NSURLRequest *request = [[NSURLRequest alloc] requestWithURL:tempURL]; 
    NSLog(@"%@", request); 
    //conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
    //[request release]; 

} 

L'URL se connecte correctement. J'ai même vérifié le type d'objet pour m'assurer que tout est correct, et tout semble bien. Aucune erreur de temps de compilation ou d'avertissement. Stack Trace & Log:

[Session started at 2011-03-09 15:02:32 -0500.] 
2011-03-09 15:02:33.807 NTR Beer Club[17702:207] URL: https://mydomain.com/path/to/file.php?action=get_app_data&subaction=singlestat&memberID=117 
2011-03-09 15:02:33.809 NTR Beer Club[17702:207] -[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0 
2011-03-09 15:02:33.811 NTR Beer Club[17702:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00db7be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00f0c5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00db96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00d29366 ___forwarding___ + 966 
    4 CoreFoundation      0x00d28f22 _CF_forwarding_prep_0 + 50 
    5 NTR Beer Club      0x00002190 -[MyStats loadMemberData] + 358 
    6 NTR Beer Club      0x000022c8 -[MyStats viewDidLoad] + 215 
    7 UIKit        0x004b64f0 -[UINib instantiateWithOwner:options:] + 1556 
    8 UIKit        0x004b8081 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168 
    9 UIKit        0x002c2943 -[UIApplication _loadMainNibFile] + 172 
    10 UIKit        0x002c34ca -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291 
    11 UIKit        0x002cddb2 -[UIApplication handleEvent:withNewEvent:] + 1533 
    12 UIKit        0x002c6202 -[UIApplication sendEvent:] + 71 
    13 UIKit        0x002cb732 _UIApplicationHandleEvent + 7576 
    14 GraphicsServices     0x016eda36 PurpleEventCallback + 1550 
    15 CoreFoundation      0x00d99064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    16 CoreFoundation      0x00cf96f7 __CFRunLoopDoSource1 + 215 
    17 CoreFoundation      0x00cf6983 __CFRunLoopRun + 979 
    18 CoreFoundation      0x00cf6240 CFRunLoopRunSpecific + 208 
    19 CoreFoundation      0x00cf6161 CFRunLoopRunInMode + 97 
    20 UIKit        0x002c2fa8 -[UIApplication _run] + 636 
    21 UIKit        0x002cf42e UIApplicationMain + 1160 
    22 NTR Beer Club      0x00001b98 main + 102 
    23 NTR Beer Club      0x00001b29 start + 53 
    24 ???         0x00000001 0x0 + 1 
) 
terminate called after throwing an instance of 'NSException' 

Répondre

2

Vous devriez faire

NSURLRequest *request = [NSURLRequest requestWithURL:tempURL]; 

Le requestWithURL: crée NSURLRequest objets qui sont autorelease -d.

Le message d'erreur réel indique "sélecteur non reconnu" car requestWithURL: est une méthode de classe, mais vous l'utilisez comme une méthode d'instance.

+0

Ahhh. C'est la partie la plus déroutante de l'apprentissage de l'Objectif-C. Mémoire. Quand allouer Quand libérer Quand init. Quand mettre à zéro. Je ne comprends pas. – Chris

+2

@Chris Règles de base: 'init' seulement après un' alloc'; les méthodes de création qui ne commencent pas par le mot "new" ou "create" retournent les objets 'autorelease'-d; quand vous 'alloc' vous devez le coupler avec un appel à 'release' ou' autorelease' quelque part dans votre code –

+1

Merci Shaggy Frog. Je vais essayer de garder cela à l'esprit. – Chris