UIImageView problem

Discussion in 'iOS Programming' started by sagarshivam, Jul 13, 2011.

  1. sagarshivam macrumors member

    May 24, 2011
    Dear all!!

    In order to display content of file (text data) , I have written the code as:
    - (void) textviewtest {
    	CGRect frame1 = CGRectMake(10, 10, 300, 400); 
            textview = [[[UITextView alloc] initWithFrame:frame1 ] autorelease];
    	textview.backgroundColor =[UIColor orangeColor];
    	textview.autocorrectionType =YES;
    	textview.editable = NO;
    	textview.clipsToBounds = NO;
    	[textview  setText: fileString ];
            [textview setFont:[UIFont fontWithName:@"Helvetica" size:16.0]];
    	[[self view] addSubview : textview ];
    And this is working properly. File contents are displayed properly on viewer.

    Now I want to display some image (png/jpeg) on some viewer again. I am trying to display images of dimension 250*250 pixels. And using the code like:

       CGRect rect=CGRectMake(10,10,300,400);
       UIImageView *image=[[[UIImageView alloc]initWithFrame:rect] autorelease];
       image.backgroundColor =[UIColor redColor];
       NSLog(@"reading image");
       [image setImage:[UIImage imageNamed:@"/Users/sagar/scrshot.png"]];
       [[self view] addSubview: image];
    But there is no image on viewer.Nothing happens!!

    Am I making any mistake?

  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    define "viewer"? I guess you just mean your view.
    And is the red color being showed or not? because I think he is having errors connecting to the .png, put it inside your project.
    Because for the rest, I don't really see issues, u tried debugging your pointer from your UIImageView?
    And are you sure it's in front of the other subviews?
  3. sagarshivam thread starter macrumors member

    May 24, 2011
    Yes, viewer means the view that I have defined here. In my case it is 'image' and 'textview'.

    Red color is visible on the viewer.I changed the image but no use. And image is not inside my project folder. I am trying to display any image file lying on my pc.

    And how to check that this viewer is in front of other subview?

    But since red color viewer is seen, so I guess it is in the front only
  4. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    Since you get the red view. it's purely the problem that it cannot load your image.
    Try to put it INSIDE your project, just name it, test1.png
    and load it as
    [UIImage imageNamed:mad:"test1.png"];

    If that works, you debugged the problem, weeee!
  5. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    What leads you to believe that you can access an image file from the /Users folder? Images referenced in this manner must reside in the application's main bundle.

Share This Page