Search code examples
iosxcodeuiimageviewxcode4.5

"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.


Solution

  • 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