how to send the xml parsing image data to ImageView.image - ios

I am working on parsing, I got the image data form the XML like Link
then i sent this to detail view controller by using shared delegate.
AppDelegate *sharedDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
imageview.image=[UIImage imageNamed:sharedDelegate.imagObj];
I got data in sharedDelegate.image but Imageview.image got only the null value.
Please help me.

If you are getting a string, then use this code :
AppDelegate *sharedDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat:#"%#",sharedDelegate.imagObj]]];
imageview.image = [UIImage imageWithData: imageData]];

Related

Show image from URL in Keyboard App Extension

I am working on keyboard app,I am trying to show image from url in the extension but code not working though this code is working fine for my iphone app
UIImageView * kanyeGifImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, cell.frame.size.width, cell.frame.size.height)];
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: #"some image url"]];
if ( data == nil )
return;
dispatch_async(dispatch_get_main_queue(), ^{
// WARNING: is the cell still using the same data by this point??
kanyeGifImage.image = [UIImage imageWithData: data];
tempImage = kanyeGifImage.image;
// kanyeGifImage.image = [self squareImageFromImage:cell.appImageView.image scaledToSize:320];
});
});
I'm guessing that the NSURL is not a web url, but a reference to a file in your bundle. Bundles are not by default shared between your main app and your extension. Read up on the section "Sharing Data with your Containing App" https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html

image are not showing on imageview. in ios

http://hauwengweb.azurewebsites.net/api/AccomodationImages/images/1
I'm trying to download image on imageView. If you will paste this url on browser it will show, but on imageView it's not showing. If you will try any other image, then the same code will work, but when I used this url, the image does not show.
The image in question seems to be a WebP image (served with the wrong MIME type of image/png), which is not a format natively supported by UIImage. However, you can use iOS-WebP to decode the image:
Add the framework, header and implementation to your project, then use:
#import "UIImage+WebP.h"
NSURL *url = [NSURL URLWithString:#"http://hauwengweb.azurewebsites.net/api/AccomodationImages/images/1"];
NSData *data = [NSData dataWithContentsOfURL:url];
imageView.image = [UIImage imageWithWebPData:data];
And please remember to do the download and decoding steps asynchronously so as not to block the main UI.
Try this?
NSURL *url = [NSURL URLWithString:#"http://hauwengweb.azurewebsites.net/api/AccomodationImages/images/1"];
NSData *data = [NSData dataWithContentsOfURL:url];
self.img.image = [UIImage imageWithData:data];
Edit
The URL you provided is not an absolute path hence the data being fetched cannot be converted into an UIImage. There is something wrong with the URL or the formatting of it.

"No visible #interface declares the selector" error

I inserted an image view in my view controller but dont actually know how to display image on it.
I tried this:
- (void)viewDidLoad
{
[super viewDidLoad];
id path = #"http://thestylishdog.com/wp-content/uploads/2009/07/cute-dog2.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImageView *firstImage = [[UIImage alloc] initWithData:data cache:NO];
}
But then it says that 'No visible #interface for UIimage declares the selector initwithData:cache'
I tried adding this line to the .h file but does not work either:
#property (nonatomic, retain) UIImageView *firstImage;
I know that the last step would be to assign that .h create class to the UIimage in the viewcontroller.
You can use try this code to add image from the path in your imageview
NSURL *url = [NSURL URLWithString:#"http://thestylishdog.com/wp-content/uploads/2009/07/cute-dog2.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
imageView = [[UIImageView alloc] initWithImage:image];
Don't forget to show your imageView as outlet to xib if you are adding through GUI otherwise add it to your view as subview
Try [[UIImage alloc] initWithData:data]; you can cache using an NSCachedURLResponse for the response.
You can use this to load images from URLs:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://..."]]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
But this will block your app until your image loads. It's best to load your images asynchronously when using images from the web. If the images are downloaded in a different thread user can keep interacting with the app. You can check this example from apple about lazy loading images: LazyTableImages
Or you can checkout this tutorial for async image download:
UItables with downloaded images

Random URL website address from core data that holds a picture to display in UIImage in iOS?

I'm new to using xcode, so any information or links would be helpful. If I had a RANDOM website url in coredata, how would I be able to direct my UIImage to get the photo from that website to display in iOS?
Let's say imageURL is a NSString * ivar or property where you hold your URL.
To get the image this should work:
NSURL *url = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *myImage = [UIImage imageWithData: imageData];
Of course you should add some error checking but this should get you into the right direction.

UIImage return Null IOS

NSURL *url = [NSURL URLWithString:
pictureUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
NSLog(#"image width:%#",image.size.width);
I am getting null from this log? The image is valid and displaying correctly?.
This is in a table cell
Try this:
NSLog(#"image width:%f",image.size.width);
Besides that, I hope you are calling this on a background thread (not within cellForRow), otherwise loading your cells will be very slow and screw up user interaction.

Resources