iOS6 UIImage导致崩溃
由于iOS6我有一个非常奇怪的UIImages问题,导致应用程序崩溃。 完整方法是这样的:iOS6 UIImage导致崩溃
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/users/show.json"];
NSDictionary *parametros = [NSDictionary dictionaryWithObjectsAndKeys:account.username, @"screen_name", nil];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:url
parameters:parametros];
[request setAccount:account];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if ([urlResponse statusCode] == 200) {
NSError *error_ = nil;
NSDictionary *userInfo = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error_];
UIImage *image = [UIImage imageWithData:[userInfo objectForKey:@"profile_image_url"]];
UIImage *image = [UIImage imageWithData:[userInfo objectForKey:@"profile_image_url"]];
dispatch_sync(dispatch_get_main_queue(), ^{
[_imageCache setObject:image forKey:account.username];
[ListAccount reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO];
});
}
}];
的问题发生在这条线
UIImage *image = [UIImage imageWithData:[userInfo objectForKey:@"profile_image_url"]];
这在iOS5的没有问题。我似乎无法找到为什么或有同样问题的人。任何建议将非常感激
崩溃如下:
2012-09-28 17:30:53.600 Catalogo[7321:c07] -[__NSCFString bytes]: unrecognized selector sent to instance 0x10eaf180
2012-09-28 17:30:53.601 Catalogo[7321:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString bytes]: unrecognized selector sent to instance 0x10eaf180'
*** First throw call stack:
(0x2aed012 0x1a28e7e 0x2b784bd 0x2adcbbc 0x2adc94e 0x2a75390 0x203630c 0x2035e7e 0x2035d98 0x10dc23d 0xf991f3 0xf98ef4 0x6c54e 0x1b9e731 0x1bad014 0x1b9d7d5 0x2a93af5 0x2a92f44 0x2a92e1b 0x2dd87e3 0x2dd8668 0xf7765c 0x79cd 0x2d45)
libc++abi.dylib: terminate called throwing an exception
以下:
[userInfo objectForKey:@"profile_image_url"]
回报Twitter个人资料图片
你需要转换的网址[userInfo objectForKey:@"profile_image_url"]
分成NSData
,然后传递给imageWithData :。
NSString * profileImageString = [userInfo objectForKey:@"profile_image_url"];
NSData * profileImageData = [profileImageString dataUsingEncoding:NSUTF8StringEncoding];
不是使用:
尝试过: NSData * data = [NSData dataWithContentsOfURL:[userInfo objectForKey:@“profile_image_url”]]; UIImage * image = [UIImage imageWithData:data]; 仍然没有运气,被抛出这个错误: - [__ NSCFString isFileURL]:无法识别的选择发送到实例0xa2218e0 – jonathanwiesel
转换的的NSString NSURL ** [NSData的dataWithContentsOfURL:[NSURL URLWithString:[USERINFO objectForKey:@ “profile_image_url”]]] ; ** – WrightsCS
尝试过上次编辑,但仍然没有运气: ***由于未捕获的异常'NSInvalidArgumentException',原因:' - [NSCache setObject:forKey:cost:]:试图插入nil值(key:enf_4eva )' – jonathanwiesel
什么是实际碰撞? –
你可以NSLog userInfo并提供有关错误的信息? –
我已根据您的请求编辑帖子 – jonathanwiesel