2012-04-10 19 views
20

Che cosa potrebbe significare questo errore?[__NSCFNumber lunghezza]: selettore non riconosciuto inviato all'istanza 0x6d21350

[__NSCFNumber length]: unrecognized selector sent to instance 0x6d21350 

Ecco il mio codice:

NSString *urlString = @"http://api.twitter.com/1/statuses/update.json"; 
    NSURL *url = [NSURL URLWithString:urlString]; 

    NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 
    [params setObject:status forKey:@"status"]; 
    [params setObject:replyToID forKey:@"in_reply_to_status_id"]; 
    [params setObject:@"1" forKey:@"include_entities"]; 

    // Build the request with our parameter 
    TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodPOST]; 

    // Attach the account object to this request 
    [request setAccount:twitterAccount]; 

    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
     if (!responseData) { 
      // inspect the contents of error 
      NSLog(@"%@", [error localizedDescription]); 

      self.alert = [[UIAlertView alloc] initWithTitle:@"HTTP error" message:@"I could not connect to the Twitter API." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
      [self.alert show]; 

      [self.replyDelegate replyRequestSuccessful:NO]; 
     } 
     else { 
      /*NSString *responseDataAsString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
      NSLog(responseDataAsString);*/ 

      NSError *error; 
      NSArray *replyResponse = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; 

      if (!replyResponse) { 
       NSLog(@"%@", [error localizedDescription]); 

       self.alert = [[UIAlertView alloc] initWithTitle:@"JSON error" message:@"I could not parse the JSON response from the Twitter API." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
       [self.alert show]; 

       [self.replyDelegate replyRequestSuccessful:NO]; 
      } 
      else { 
       [self.replyDelegate replyRequestSuccessful:YES]; 
      } 
     } 
    }]; 

ho provato debuggin, e muore una volta che entra nel performRequestWithHandler. Va il blocco else e muore con l'errore sopra.

risposta

67

Significa che si sta passando un NSNumber in cui il codice chiamato si aspetta un NSString o qualche altro oggetto che ha un metodo length. Puoi dire a Xcode di interrompere le eccezioni in modo da vedere dove viene chiamato esattamente il metodo length.

+7

Più probabile, c'è un problema con la sua gestione della memoria, e il runtime/framework si aspetta un NSString che non c'è più (dalla deallocazione prematura) e un NSNumber è stato allocato lì. Se si tenta di inviare 'length' a un' NSNumber', il compilatore si spera che ti avverta. – dreamlax

+0

Non se il 'NSNumber' viene passato in un dizionario o attraverso un'altra interfaccia che cancella i tipi. Ma hai ragione, è abbastanza probabile che stia rilasciando qualcosa. Potrebbe essere una buona idea provare con 'NSZombieEnabled'. – zoul

+0

Cosa intendi con "cancella i tipi"? – dreamlax

6

Specificamente questa riga di codice:

[params setObject:replyToID forKey:@"in_reply_to_status_id"]; 

il replyToID non è una stringa o ha un metodo length. Se non si dispone di questo o se si converte lo replyToID in una stringa prima di impostarlo in parametri, dovrebbe funzionare.

Problemi correlati