关于ARC开发中的ARC和语义问题的错误

时间:2013-02-05 12:00:51

标签: iphone ios ios6

尝试从远程Web服务器解析XML文件时,我可以成功解析XML文件中的数据。从XML文件中,我尝试检索图像URL并将其分配给视图控制器的UIImageView。这里得到以下错误,

  • ARC Semantic Issue: No known class method for selector 'imageWithContentsOfUrl:'

  • Sematic Issue: Incompatible pointer types sending 'NSURL *__strong' to parameter of type 'NSString *'

以下是我的代码,

//My View Controller
[super viewDidLoad];
 NSURL *url = [NSURL URLWithString:@"http://sample.com/Products.xml"];
 EGSParser *parser = [[EGSParser alloc] init];
// Error in below line( here firstImage is a UIImageView property)
 self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]]; 
 if ([parser loadXMLByURL:url]) {
    NSLog(@"success; products=%@",parser.products);
 self.xmlProductsResults = parser.products;
}
else
{
 NSLog(@"Log Fail");
}

请建议我解决这个问题。

4 个答案:

答案 0 :(得分:1)

更改此行:

 self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]]; 

 self.firstImage.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@",url]]; 

答案 1 :(得分:1)

试试这个: -

替换

self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]];

NSData *mydata = [[NSData alloc] initWithContentsOfURL:url];
self.firstImage.image = [UIImage imageWithData:mydata];

希望它可以帮助你..

答案 2 :(得分:1)

应该有效,只需替换

self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]] ;

self.firstImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

注意:NSUrl网址应该是图片网址

答案 3 :(得分:1)

你有一个拼写错误,它是imageWithContentsOfURL:(大写网址),而不是imageWithContentsOfUrl:。这就是为什么不能识别类方法的原因。

修改:此外,它是CIImage而非UIImage的方法。

相关问题