ios [__NSCFNumber length]:无法识别的选择器发送到实例 0x6d21350
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10095459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
[__NSCFNumber length]: unrecognized selector sent to instance 0x6d21350
提问by Richard Knop
What could this error mean?
这个错误意味着什么?
[__NSCFNumber length]: unrecognized selector sent to instance 0x6d21350
Here is my code:
这是我的代码:
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];
}
}
}];
I tried debuggin, and it dies once it enters the performRequestWithHandler. It goes the else block and dies with the error above.
我试过 debuggin,一旦它进入 performRequestWithHandler 就会死掉。它进入 else 块并因上述错误而死亡。
回答by zoul
It means that you are passing an NSNumber
where the called code expects an NSString
or some other object that has a length
method. You can tell Xcode to break on exceptions so that you see where exactly the length
method gets called.
这意味着您正在传递一个NSNumber
被调用代码需要一个NSString
或其他具有length
方法的对象的地方。您可以告诉 Xcode 在异常时中断,以便您查看length
调用该方法的确切位置。
回答by Sau Sheong
Specifically this line of code:
特别是这行代码:
[params setObject:replyToID forKey:@"in_reply_to_status_id"];
the replyToID
is not a String or has a method length
. If you don't have this, or if you convert the replyToID
to a String before setting it in params it should work.
的replyToID
是不是一个字符串或有一个方法length
。如果你没有这个,或者如果你replyToID
在将它设置为 params 之前将它转换为一个字符串,它应该可以工作。