Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 4, 2010, 09:48 PM   #1
CosmicChild87
macrumors newbie
 
Join Date: Nov 2010
Location: England
UIImageView Wont Display Image

Not having a good day today - still trying to learn obj - c and this is my 2nd stupid problem in one day

Im using the following code to load the filename of an image from a database into a UIImage - and from that show it in a UIImage View

Code:
NSArray *documentPaths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDir2 = [documentPaths2 objectAtIndex:0];			 
NSLog(@"Trying to read image from %@",[documentsDir2 stringByAppendingPathComponent:[NSString stringWithFormat:@"%s",sqlite3_column_text(compiledStatement, 2)]]);
UIImage *logoImage = [UIImage imageNamed:[documentsDir2 stringByAppendingPathComponent:[NSString stringWithFormat:@"%s",sqlite3_column_text(compiledStatement, 2)]]];  
NSLog(@"Image filepath %@",[NSString stringWithFormat:@"%s",sqlite3_column_text(compiledStatement, 2)]);
theImageEditView.image = logoImage;
[logoImage release];
In the debugger im getting the following;
2010-11-05 02:41:26.310 Field and Track[94325:207] Trying to read image from /Users/alan/Library/Application Support/iPhone Simulator/4.2/Applications/2A8DFD5D-BC25-437E-A2B2-850BBA53D1C0/Documents/India.JPG
2010-11-05 02:41:26.313 Field and Track[94325:207] Image filepath India.JPG
2010-11-05 02:41:26.314 Field and Track[94325:207] Logo done

and having checked the filepath - the link is right to the image (when running in simulator at least)

The UIImaveView is linked up correctly, and @synthesized but for some reason when i run the code, i get no errors but the image does not display in the ImageView

Thanks in advance

Alan
CosmicChild87 is offline   0 Reply With Quote
Old Nov 5, 2010, 12:46 AM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Two things come to mind.

1. Why aren't you checking for nil returned from imageNamed?

2. This code is wrong, because you don't own logoImage:
Code:
[logoImage release];
Read this:
http://developer.apple.com/library/i...emoryMgmt.html
chown33 is offline   0 Reply With Quote
Old Nov 5, 2010, 01:20 AM   #3
CosmicChild87
Thread Starter
macrumors newbie
 
Join Date: Nov 2010
Location: England
1) Basically i just want to get it working, and at the moment its only me i know that all the rows in the DB have an image - for now

2)Ok, but that won't stop the image from showing
__________________
MacBook Pro - 2.8GHz Intel, 4GB RAM, 320GB
MacMini - 1.25GHz PPc, 512MB RAM, 40GB
iPhone 4 - 32GB, Black
iPad - 32GB, Wi-Fi
CosmicChild87 is offline   0 Reply With Quote
Old Nov 5, 2010, 03:04 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
imageNamed: does not expect a full path, simply the image name in the resources directory.
robbieduncan is offline   0 Reply With Quote
Old Nov 5, 2010, 12:19 PM   #5
CosmicChild87
Thread Starter
macrumors newbie
 
Join Date: Nov 2010
Location: England
Ah, thats saving alot of work thanks!
Im sure im doing something really basic wrong but for now im forcing the image to try and load a predifined image just to get it working so im sending it
Code:
UIImage *logoImage = [UIImage imageNamed:@"India.JPG"];  

			///Users/alan/Library/Application Support/iPhone Simulator/4.2/Applications/2A8DFD5D-BC25-437E-A2B2-850BBA53D1C0/Documents/India.JPG
			NSLog(@"Image filepath %@",[NSString stringWithFormat:@"%s",sqlite3_column_text(compiledStatement, 2)]);
			theImageEditView.image = logoImage;
and ive got

Code:
}
.
.
.
	 IBOutlet UIImageView *theImageEditView;
	 IBOutlet UITextField *editTeamName;
	 NSNumber *workingRowID;
	 
	
}


@property(retain,nonatomic) UIImageView *theImageEditView;
in my .h file?
__________________
MacBook Pro - 2.8GHz Intel, 4GB RAM, 320GB
MacMini - 1.25GHz PPc, 512MB RAM, 40GB
iPhone 4 - 32GB, Black
iPad - 32GB, Wi-Fi
CosmicChild87 is offline   0 Reply With Quote
Old Nov 5, 2010, 01:24 PM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
What's the question now?
__________________
dejo is offline   0 Reply With Quote
Old Nov 5, 2010, 02:05 PM   #7
CosmicChild87
Thread Starter
macrumors newbie
 
Join Date: Nov 2010
Location: England
Same, thing no image is showing
__________________
MacBook Pro - 2.8GHz Intel, 4GB RAM, 320GB
MacMini - 1.25GHz PPc, 512MB RAM, 40GB
iPhone 4 - 32GB, Black
iPad - 32GB, Wi-Fi
CosmicChild87 is offline   0 Reply With Quote
Old Nov 5, 2010, 02:21 PM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Make sure you pay attention to chown33's earlier post. Basic debugging is better than "I just want to get it working", because it should reveal why it's not working in the first place. If imageNamed: returns a nil, no image will be shown. If that's the problem, you need to examine why more deeply. Is there no image named "India.JPG"? (Remember, case is significant.) If you're pretty sure that's correct, perhaps it's an issue with imageNamed: not finding the image where it thinks it should be finding it. Etc.
__________________
dejo is offline   0 Reply With Quote
Old Nov 5, 2010, 02:30 PM   #9
CosmicChild87
Thread Starter
macrumors newbie
 
Join Date: Nov 2010
Location: England
I have done some NSLogs to get to this stage - the information is coming out of the database fine, and "India.JPG" does exist and is stored in the applications documents directory.

I thought that if I hard code the image to the UIImage I am debugging because it will allow me to tell if my problem is with the actual image, or with the UIImage or UIImageView - thats why i did it

To the best of my knowledge now thats where I'm trying to load the image from, or am I wrong?

Thanks again

Alan
__________________
MacBook Pro - 2.8GHz Intel, 4GB RAM, 320GB
MacMini - 1.25GHz PPc, 512MB RAM, 40GB
iPhone 4 - 32GB, Black
iPad - 32GB, Wi-Fi
CosmicChild87 is offline   0 Reply With Quote
Old Nov 5, 2010, 02:54 PM   #10
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by CosmicChild87 View Post
I have done some NSLogs to get to this stage - the information is coming out of the database fine, and "India.JPG" does exist and is stored in the applications documents directory.
Neither of which answers the question: Is imageNamed returning nil?

Answering this fundamental question divides the problem into two separately debuggable parts:
  1. If imageNamed returns nil, then the issue lies with loading the image.
  2. If imageNamed returns a non-nil object, then the issue lies with displaying the image.
Remember that you can't display nil, so it is essential to answer this question in order to determine in which half the real problem actually lies.

Also notice that imageNamed doesn't load a specific image at a specific path. If you want that to happen, you're doing it wrong. You need to use imageWithContentsOfFile. Again, you should check its returned value for nil, to ascertain whether it worked or not. If it doesn't load the image, then you have the same two separate debuggable parts: loading the image and displaying the image.
chown33 is offline   0 Reply With Quote
Old Nov 5, 2010, 02:55 PM   #11
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
I think the imageNamed: is a bit of a red-herring in your case since eventually you want to load images from the Documents folder and I'm pretty sure imageNamed: only loads from the application's main bundle. I think you would be better off pursuing using imageWithContentsOfFile: instead.
__________________
dejo is offline   0 Reply With Quote
Old Nov 5, 2010, 03:41 PM   #12
CosmicChild87
Thread Starter
macrumors newbie
 
Join Date: Nov 2010
Location: England
Thank you dejo, thats where I was going wrong and I've got it working now

Code:
NSString *filePath = [NSString stringWithFormat:@"%@/%s", documentsDir2,sqlite3_column_text(compiledStatement, 2)];
			UIImage *img = [[[UIImage alloc] initWithContentsOfFile:filePath] autorelease];
did the trick perfectly

Alan
__________________
MacBook Pro - 2.8GHz Intel, 4GB RAM, 320GB
MacMini - 1.25GHz PPc, 512MB RAM, 40GB
iPhone 4 - 32GB, Black
iPad - 32GB, Wi-Fi
CosmicChild87 is offline   0 Reply With Quote
Old Nov 5, 2010, 03:54 PM   #13
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Just a suggestion: use stringByAppendingPathComponent: when constructing a path. It's the preferred method.
__________________

Last edited by dejo; Nov 5, 2010 at 04:08 PM. Reason: fixed typo
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
ipad, iphone, uiimage, uiimageview, xcode

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Macbook Pro no display image kris-hm MacBook Pro 12 Apr 4, 2014 09:38 AM
Iphone wont display images maps85 iPhone Tips, Help and Troubleshooting 2 Mar 4, 2013 02:18 AM
how to display image in UIImageView in a specifc block of window in iphone mark.p iPhone/iPad Programming 1 Nov 27, 2012 11:36 AM
Bizarre image on Thunderbolt display jorman Mac Peripherals 3 Nov 11, 2012 01:13 PM
Folder Won't Display Image Previews (4th Display Option) trevor2522 Mac Basics and Help 5 Sep 11, 2012 08:59 AM

Forum Jump

All times are GMT -5. The time now is 09:37 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC