UIButton CustomButton Image Not Appearing - objective-c

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!

Related

Creating a button to switch between xib files

Currently my custom keyboard has only one layout: the Qwerty keyboard is only letters. I want to create a button that will switch to the numbers and symbol part of every keyboard. Because I am new to programming I figured I should make two different xib files: one with letters and the other with numbers and symbols. In order to switch between the two xib files (Keyboard.xib and AltKeyboard.xib) I tried to create a button in the AltKeyboard.xib that would go to the Keyboard.xib and this is my code:
#pragma mark AltKeyboard
-(void)addGesturesToAltKeyboard{
[self.altKeyboard.altKey addTarget:self action:#selector(initWithNibName:"Keyboard" bundle: nil) forControlEvents:UIControlEventTouchUpInside];
}
However, this does not work, so I was wondering if I could get some advice in what I could do now.

why image is not displayed in UIImageView?

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];

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 not receiving touches when added to subview, but does when added to main view

Basically I have a main screen that comes up with a background image and three menu choices across the bottom of the screen. When I add these 4 components to the RootViewController's view, everything works fine., but if I do something like
_mainContainer = [[UIView alloc] init];
self.view = _mainContainer;
_firstScreen = [[UIView alloc] initWithFrame:self.view.frame];
"some code here setting up the subviews"
[buttonLeft addTarget:self action:#selector(startGame) forControlEvents:UIControlEventTouchUpInside];
[_firstScreen addSubview:mainMenuBackground];
[_firstScreen addSubview:buttonLeft];
[_firstScreen addSubview:buttonMid];
[_firstScreen addSubview:buttonRight];
[_mainContainer addSubview:_firstScreen];
Essentially if I add everything directly to _mainContainer, the buttons work, if I add it to _firstScreen, then add _firstScreen they don't work.
User interaction is enabled on _firstScreen. I do something similar later in my app and it works fine. Also, not sure if this has anything to do with it, but despite my screen being displayed in landscape, and all options in the plist being set to landscape only, when I run a transition, like flipFromBottom (or whatever its called), my app thinks the "bottom" is with the screen being in portrait until I move to another group of subviews in my app. (So basically the title screen is acting screwy).
I looked everywhere for a solution, hopefully I am not missing something basic.
Hey what is mainMenuBackground?, if its a image , their is no need to make it as a subView, instead, the correct way is to set it as a background image. I hope this will solve your problem

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