Error on ARC and semantic Issues in iPhone development - iphone

When trying to Parse the XML file from remote web server, I can parse the data from XML file successfully. From the XML file i tried to retrieve an image URL and assign it to a UIImageView for a view controller. here am getting the following Error,
ARC Semantic Issue: No known class method for selector 'imageWithContentsOfUrl:'
Sematic Issue: Incompatible pointer types sending 'NSURL *__strong' to parameter of type 'NSString *'
Below is my code,
//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");
}
Kindly Suggest me an idea to solve this.

Try this :-
Replace
self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]];
with
NSData *mydata = [[NSData alloc] initWithContentsOfURL:url];
self.firstImage.image = [UIImage imageWithData:mydata];
Hope it helps you..

Change this line :
self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]];
to
self.firstImage.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#",url]];

You have a typo, it is imageWithContentsOfURL: (capital URL) and not imageWithContentsOfUrl:. That's why the class method is not recognized.
Edit: also, it is a method of CIImage and not UIImage.

Should work, just replace
self.firstImage.image = [UIImage imageWithContentsOfUrl:[NSURL URLWithString:url]] ;
with
self.firstImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
NB: the NSUrl url should be an image url

Related

how can I display UIImage from image url

The code below works fine if I give statically but
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"http://4cing.com/mobile_app/uploads/pageicon/6.jpg"]]]];
Same code - I am passing the image url name dynamically it's not working
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]]]];
You need to verify the NSArray contents. Log out the objects of the array:
NSLog(#"imagename = %#",[imagename description]);
Also, a side-note - might want to think about loading that image dynamically. I wrote a class that makes this pretty painless:
https://stackoverflow.com/a/9786513/585320
The answer is geared toward using in TableViews (where lag would really hurt performance), but you can (and I do) use this for any web image loading. This keeps the UI fluid and is very fast.
NSMutableArray *imagename = [[NSMutableArray alloc] initWithObjects:#"http://4cing.com/mobile_app/uploads/pageicon/6.jpg", nil];
UIImageView *imgDescView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 200, 200)];
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]]]]];
it is working ... i think u r not creating array properly.
Hi create url in this manner
[NSURL URLWithString:[[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
i think it will work and will resolve ur problem.

how to display image in UIImageView in a specifc block of window in iphone

I have a window in which I want to display an image in a specific block of that window. The image is retrieved from the local XML file. I parsed the XML file and got the image value in the log, but I don't know how to put it in that specific block. The below image pasted for the reference.
The arrow mark represents that within this UIImageView I need to get the image. Also, I doubt that I need to mention any name for reference to UIIMageView in storyboard. Suggest me an idea.
Edited
My parser code:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Sample.xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:theParser]
After this I am using this code for getting image:
UIImage *image = [UIImage imageWithContentsOfFile:#"/Users/administrator/Desktop/imageApp/resources/Main_pic1.png"];
After this I don't know how to continue.
Yes, you have to create IBOutlet in .h file
like IBOutlet UIImageView *imgview; and connect imgview with your UIImageview from xib.
After that you can set image to image view.
NSURL *URL = [NSURL URLWithString:[your url which u get form local xml]];
NSData *imageData = [NSData dataWithContentsOfURL:URL];
UIImage *image = [UIImage imageWithData:imageData];
imgview.image=image;
Ttry this, It may help you.
You can directly pass the url image to Uiimageview by :
YourImageView.image = [UIImage imageWithContentsOfURL:YourUrl];
It's possible to do the equivalent by going through NSData, but it's a bad idea. Instead, the image should be downloaded asynchronously using NSURLConnection, and only once it's fully downloaded should it be converted into a UIImage and assigned to the image view.
Save all your urls in an say NSMutableArry *UrlArray then
int x = 0;
int y = 10;
for (int i = 0; i< [UrlArray]; i++)
{
UIImageView *imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(3+x,y, 80,
80)]autorelease];
imageView.backgroundColor = [UIColor blueColor];
if (x >= 300)
{
x = 0;
y = y+imageView.frame.size.height+3;
imageView.frame = CGRectMake(x+3 , y, 80, 80);
}
CIImage *beginImage = [CIImage imageWithContentsOfURL:[UrlArray ObjectAtIndex:i]];
imageView.image = [UIImage imageWithCIImage:beginImage];
x = x+imageView.frame.size.width+5;
[self.view addSubview:imageView];
}
will do the work i guess;

SignalR: sometimes no data returns when trying to load images

Once in a while when loading image like this:
dispatch_async(dispatch_get_global_queue(0, 0), ^
{
NSData *data = [[NSData alloc] initWithContentsOfURL:someImgUrl.jpg];
if (data == nil)
{
NSLog( #"data is nil with img url:%#" ,imgUrl);
return;
}
dispatch_async(dispatch_get_main_queue(), ^
{
img.image = [UIImage imageWithData:data];
});
});
my data is nil.
I used fiddler to sniff that, and saw that everytime it happened no request is shown in fiddler!
The only times it NEVER happens are
When I don't use SignalR client in my app.
Downloading the image synchronically:
NSData * imageData = [[NSData alloc] initWithContentsOfURL:someImgUrl.jpg ];
img.image = [UIImage imageWithData: imageData];
The way I initialize SignalR is this:
NSString *listenurl = [NSString stringWithFormat:#"%#/%#", SERVICE_URL, #"/echo"];
mConnection = [SRConnection connectionWithURL:listenurl];
[mConnection setDelegate:self];
[mConnection start:[[SRLongPollingTransport alloc] init]];
Anyone else use signalR client in ios and exprience this behaviour?
It seems that problem only happens when SignalR listens with the same domain name to the server where you try to load images from.
So the (lame) solution so far that I found is buy a second domain and listen to that one.
Don't know why it happens though...

iPhone: Problem loading images from NSURL

I have array of image url. I want to show the images into UIImageView.
Now I convert the URL to NSData and then convert that into UIImage and then try to load that into UIImageView.
But it takes a lot of time to do this.
Is there a better way where in I can load the images in a faster and better manner?
Despite all of the answers on here telling you to do this in one line of code, it will sadly make no difference to the URL connection speed OR data / image decoding. If you want a faster way to TYPE the code then fine, but I would use category added to UIImageView....
#interface UIImageView (URL)
- (void)loadFromUrl:(NSString *)aUrl;
#end
#implementation UIImageView (URL)
- (void)loadFromUrl:(NSString *)aUrl {
NSURL *url = [NSURL urlWithString:aUrl];
NSData *data = [NSData dataWithContentsOfURL:url]
UIImage *image = [UIImage imageWithData:data];
if(image != nil) {
[self setImage:image];
}
}
#end
Now you can include the header and do...
[myImageView loadFromUrl:#"http://myurl.com/image.jpg"];
For more categories (I will be adding this one to my list!) check here. Those are all my useful ones, you may find them useful too! :)
Use everything in a single statement.
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]]];
[UIImage imageWithData:[NSData dataWithContentsOfURL:]]
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl]];
try this:-
image is UIImage and imageView is UIImageView
NSData *receivedData = [NSData dataWithContentsOfURL:#"yoururl"];
self.image=nil;
UIImage *img = [[UIImage alloc] initWithData:receivedData ];
self.image = img;
[img release];
[self.imageView setImage:self.image];

Using an NSString and UIImageView to load image from URL, failing on some URLs

I've got some code to load an image from a URL, it seems to work ok. Unless the URL contains curly brackets. This seems like it is a string formatting problem? I can't figure it out.
ex
#"http://site/image.png //works
#"http://site/{image}.png //doesn't work
NSString* mapURL = #"http://site.com/directory/{map}.png";
NSLog(mapURL);
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
[imageView setImage:image];
[imageData release];
[image release];
thanks
i found this helpful
http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/