why image is not displayed in UIImageView? - objective-c

UIImage *image = [UIImage imageNamed:[currentPhoto fileName]];
NSLog(#"%#",[currentPhoto fileName]);
[self.currentImage setImage:image];
its displays the correct image name in debug area
which i want to display on UIImageView. currentImage is outlet hooked in .h file
Is it because of new Auto-layout feater of iOS 6 i am not getting it.
It used to work in iOS 5.
My purpose is to display image in an UIImageView on a particular Scene
I have also tried to set Default image which i have copied in my project folder.
But i am getting an error debug area as follows:
Could not load the "myImage.png" image referenced from a nib in the bundle with identifier "com.xxx.xxx"

Make sure that image name carries the extension(.jpg/.png) as well. Also have you defined an iBoutlet for the imageView??
Also if the problem is with autolayout,you can disable it in the Xib. Learn it from here.
http://www.goodbyehelicopter.com/2012/02/arggh-xcode-4-3-auto-layout-is-on-by-default-how-to-turn-off-auto-layout/

When you go to File-->Add Files "ProjectName"
Below windows pops up.
And Default option selected by Xcode was
"Create folder references for any added folders" as shown pic below
which was producing
Error(in Debug area) :
Could not load the "myImage.png" image referenced from a nib in the bundle with identifier "com.xxx.xxx"
Solution to above Problem :
Select "Create groups for any added folders" which Xcode generally select was not the case this time.
Solution is so simple but sometimes silly mistakes happens.

If your image is not added to the project, it wont be available for imageNamed call.To load the image which is not added to the project use this call
UIImage * image = [UIImage imageWithContentsOfFile:imgFilePath];

Related

Strange UIImageView issue

I added a UIImageView to my View Controller's main view using interface builder.
Then I just set the image of the UIImageView in the properties.
When I run the app I can't see the image. What can be wrong? Thanks
PS. On the XIB file, if I select the image, I can see it - once I remove focus
from it, it seems like it went to the "back" of the main view (because it is still there, I can see it in the "Objects" window of the XIB file).
pps. It works if I use a different image. Could it be that it was because previous image was with transparent background? (although it still had some icon).

Custom UIButton background image showing in iOS 6 but not iOS 5

I set the button background in the interface builder, but that wasn't showing up so I set it programmatically. All (but one button... why?) shows on the simulator but never show on a device.
I get this output:
Could not load the "gray_button.png" image referenced from a nib in the bundle with identifier "com.example.ios"
This is the code:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.getMyTripButton setBackgroundImage:[UIImage imageWithContentsOfFile:
[[self getFullPathname] stringByAppendingPathComponent:#"images/gray_button.png"]]
forState:UIControlStateNormal];
[self.popupButton setBackgroundImage:[UIImage imageWithContentsOfFile:
[[self getFullPathname] stringByAppendingPathComponent:#"images/gray_button.png"]]
forState:UIControlStateNormal];
[self.viewOurPackages reloadData];
}
I have also tried replacing imageWithContentsOfFile with imageNamed and both yield the same results.
I have added the images directory in my Project > Targets > Build Phases > Copy Bundle Resources, but I think this is where it all starts to go wrong and I can't figure out why. Possibly because it's a directory?
I would like to point out that I have double and triple checked that it is not a capitalization/case-sensitive issue.
UPDATE: I have solved the one button not showing. It would seem that real issue is that the images show on iOS6 and NOT on iOS5.
What worked for me was one (or a combination) of the following 3 things:
Make sure your image file is formatted correctly. Sometimes png files need a little coercing. (I think this specifically was my problem)
Make sure your button is of type Custom in the Interface Builder or UIButtonTypeCustom.
If you are setting the image in Interface Builder and it's still not showing, set it explicitly in the code using [button setBackgroundImage:image forState:UIControlStateNormal] (or [button setImage:image forState:UIControlStateNormal] depending on which one you need.
If you are adding a folder to the copy bundles, then instead of referencing the file as gray_button.png, you should reference if from code or xib You will have to include the directory in the name too such as directory/gray_button.png
Steph,
If you used #synthesize for the button in the .h file, then getters and setters are automatically created. Thus (this is a longshot and just a thought) having the name getMyTripButton could be confusing Xcode somehow. Try renaming the variable?
As far as the image not loading... for one of the buttons and not the other... da faq? Is this the only places that gray_button.png is getting called? (for example, you aren't modifying that button somewhere else that may tell it to use that image again). Have you tried putting it in the same directory as the nib that is using it? are you sure getMyTripButton is properly tied from the nib to the code?
Last thing I can think of for now:
you said
I set the button background in the interface builder, but that wasn't
showing up so I set it programmatically. All (but one button... why?)
shows on the simulator but never show on a device
do you have popupButton's background image also set in the nib/interface builder? if you already have it set there and are setting it again here, it may be that it isn't really getting set in the code at all and is just using what is in interface builder which could explain why getMyTripButton may not be showing up/showing the background image.
If I think of anything else that could be causing the issue i'll edit this post. Good luck, and hang in there.

UIButton CustomButton Image Not Appearing

I have a custom button with an image. I had to change the image so I deleted the old one and placed a new one with the same name into my project. But now, no image appears for the button, but if I click on the button it works fine. Here is the code:
//before #implementation
static NSString *kdetailsIcon = #"details.png";
//in a helper method
UIButton *detailsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[detailsButton setFrame:CGRectMake(276, 8, 44, 44)];
[detailsButton setImage:[UIImage imageNamed:kdetailsIcon] forState:UIControlStateNormal];
[detailsButton addTarget:self action:#selector(showDetailView) forControlEvents:UIControlEventTouchUpInside];
[infoBar addSubview:detailsButton];
I figure the problem is actually something with xcode rather than my code, but I have tried deleting the image files and re-adding them, cleaning the project, deleting the app from my phone before compiling, deleting the derived data, everything I can think of. Any help would be greatly appreciated.
-First make a clean in your project click in product/clean.
-Delete this image from directory of your project in Xcode. Them add this image into your paste project. Go to XCode again, in your project go File / Add Files to project_Name.
search and choose your image and sucess. If not Success,Close/Open Project again.if not sucess again your writing wrong name/extensions of your image!

UIImageView in PopOver not changing?

I'm making an app and it has multiple button that when you press them it open a pop over view (using Storyboard.) The image is blank in IB (I set it that way) and my buttons are ment to populate the image view. This is the code I'm using:
[popoverImageView setImage:[UIImage imageNamed:#"telegraph.jpeg"]];
Steps (in order run)
Popover opens
Above code is run
Some notes:
The image is case matched.
The image is built-into the bundle
Anyone able to shed some light?
if you haven't read Apples View Controller Catalog for iOS you should read it.
I would check your popoverImageView's viewDidLoad/viewWillLoad and see if it is clearing your View before it presents itself.
Check your popoverImageView's properties they may not be linked properly
Enjoy using the storyboard I find it a pain for Popover's
Without any information regarding the the interface for your Popover and the implementation of the function where you call [popoverImageView setImage:[UIImage imageNamed:#"telegraph.jpeg"]]; and your setImage function i can't be sure of your exact problem

Type doesn't look smooth when importing Nib file with NSViewController

I'm importing a seperate nib file using a NSViewController. In my windowController, the nib is loaded using the following code:
_schedulesViewController = [[SchedulesViewController alloc] initWithNibName:#"Schedules" bundle:nil];
[_inspectorView addSubview:[_schedulesViewController view]];
There is one problem: the text from the schedules nib file doesn't look smooth. It seems that there is a scaling problem. Here's a screen capture:
The text just doesn't look anti-aliased. In xCode all the labels are looking bad too. What could be wrong?
Oke I have found the solution to my problem. Just disable 'Core Animation Layer' for the view you have problems with. You can find this checkbox under the View Effects Inspector. Now the text looks smooth again.