Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sagarshivam

macrumors member
Original poster
May 24, 2011
51
0
Dear all!!

In order to display content of file (text data) , I have written the code as:
Code:
- (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:

Code:
   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
 
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?
 
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
 
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!
 
Code:
   CGRect rect=CGRectMake(10,10,300,400);
   UIImageView *image=[[[UIImageView alloc]initWithFrame:rect] autorelease];
   image.backgroundColor =[UIColor redColor];
   NSLog(@"reading image");
   [image setImage:[UIImage [COLOR="Red"][B]imageNamed:@"/Users/sagar/scrshot.png"[/B][/COLOR]]];
   [[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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.