Search code examples
iphoneiosxcodeuiimageview

identify if there is image on the UIImageview


I am having trouble on identifying if there is an image on the UIImageView.

First of all, i have a static table with uiimageview inside. when user press new page or load the data, they both proceed to the same static table.

But now i want the uiimageview on the new page could show some image placeholder to tell the user can insert pic there. However for the old page with image data, i want to the placeholder to disappear when there is image inside the UIImageView.

How can i do that? I am using the code below to load the data;

- (void)viewDidLoad 
{
   self.set11.image = [UIImage imageWithData:[self.role valueForKey:@"set1"]];
    self.set111.image = [UIImage imageWithData:[self.role valueForKey:@"set1"]];
     self.topview.image = [UIImage imageWithData:[self.role valueForKey:@"toppic"]];}

Solution

  • Use :

    if(imageView.image){
       //image in UIIMageView
    }else{
       //No image !!!
    }
    

    in your case

    self.set11.image = [UIImage imageWithData:[self.role valueForKey:@"set1"]];
    if(self.set11.image){
     //image in UIIMageView
    }else{
     //No image !!!
    }