[__NSCFNumber length]:无法识别的选择器发送到实例0x6d21350

时间:2012-04-10 19:51:20

标签: iphone ios xcode

这个错误意味着什么?

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

这是我的代码:

    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];
            }
        }
    }];

我尝试了debuggin,一旦进入performRequestWithHandler就会死掉。它会进入else块并因上述错误而死亡。

2 个答案:

答案 0 :(得分:69)

这意味着您传递NSNumber,其中被调用代码需要NSString或其他具有length方法的对象。您可以告诉Xcode中断异常,以便您可以看到length方法的确切位置。

答案 1 :(得分:6)

特别是这行代码:

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

replyToID不是字符串或方法length。如果您没有这个,或者在将replyToID设置为字符串之前将其转换为字符串,它应该可以正常工作。