PDA

View Full Version : UIImageView problem




sagarshivam
Jul 13, 2011, 11:22 PM
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?


Thanks



jnoxx
Jul 14, 2011, 02:16 AM
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?

sagarshivam
Jul 14, 2011, 04:22 AM
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

jnoxx
Jul 14, 2011, 05:19 AM
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:@"test1.png"];

If that works, you debugged the problem, weeee!

dejo
Jul 14, 2011, 12:45 PM
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];


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.