Custom UIButton background image showing in iOS 6 but not iOS 5 - objective-c

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.

Related

Button does not react

I have a strange behaviour with an NSButton. It works normal until I do so voodoo somewhere else in my app. Right then the button does no longer react on click events. It still looks normal (so not disabled). It just does not do anything when I click it. Any idea where I should look in the properties of NSButton that might have been changed accidentally? (Quite sure I did not touch the button itself.)
Ensure your button is in a 'touchable' zone in its superView. I mean It have ro be placed inside it superView bounds (If not, you can see It, depending on Clipping properties, and you can't interact with It). In order to check it, set a color to your container view.
Also check userInteraction is enabled...
Hope It helps.
If your button is just not giving the animation, it might be an Xcode bug. I had a similar problem before, and I filed a bug, and it got fixed on the next Xcode version. Check out my SO question. Toolbar bar button item not working properly in SplitViewController
If you really need to give it an animation, you could probably do it in code with something like this. Please note that this is untested so it may not work, or you might need some fixing, but you get the idea :)
- (IBAction)buttonAction:(id)sender {
self.button.titleLabel.textColor = [UIColor lightGrayColor];
// Action
self.button.titleLabel.textColor = [UIColor darkTextColor];
// Or with delay
[self performSelector:#selector(changeButtonColor) withObject:nil afterDelay:0.1];
}
I figured it out. The button opened a transient popover. In order to close this popover due to an action I had coded
view.window!.orderOut(self)
After replacing it by
view.window!.performClose(self)
the strange effect was gone. I'm not sure, but this looks like a bug in the Swift runtime. I'll report it and see what comes out.

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

Segmented Control not Working

I've been working through a tutorial on raywenderlich.com called Objectively Speaking: A Crash Course in Objective-C. In the tutorial they use a segmented control, which to my understanding I've connected correctly in IB. I've tried posting my problem but after 5 days I still haven't had any help.
I suspect the problem is something like a connection issue. Could someone please look at my project and let me know where I've gone wrong. The zip files can be found here: Options, Options, Options.
You have two segmented controls in your XIB, one on top of the other.
The problem is that the bottom segmented control is hooked up via the IBOutlet, but you're actually selecting the segmented index of the top one.
To fix it, delete the bottom segmented control (the one with out constraints) and hook up the IBOutlet to the single remaining segmented control.
you need to write your listener yourself.
[urSegmentControl addTarget:self action:#selector(segmentControlValueChangedListener:) forControlEvents:UIControlEventValueChanged];
If You want to do it in interface builder:
First of all - open ViewController.m class file and create function like this - it will be called, when You change segment:
Then open ViewController.xib and with second mouse button tap-and-hold on Segmented Control instance - and pull to File Responder. Release. It will show up a view like this:
Select newly created function name. That's it - now, when value segment value will be changed, quote_opt_touch function will be called, and in debugger You will see "abc".
Also - You had Two segmented controls. Remove one of them.
Do this in appDelegate.m class and it will work. Its happening because you are not below than iOS 5.
#synthesize window;
#synthesize viewController;
Look at your xib file. You have two instances of the segmentedcontrol declared. You need to remove the bottom one and re-connect the top one to the outlet.

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

NSView (Content View) as firstResponder

I have a Content View that I use in my preferences nib.
I use a method to change the font of a NSTextView in my app.
This Content View has to be set as firstResponder to get messages from my changeTextFont: method, but since it's not a window it doesn't have a firstResponder. As a result, it does not change the text font at all... does anyone have a workaround for this ?
Thanks a bunch guys.
I could make the sample project work without specifying [self window] as first responder. What I did was:
in (void)changeTextFont:(id)sender, I replaced the statement:
[[self window] makeFirstResponder:[self window]];
with lines:
[[NSFontManager sharedFontManager] setAction:#selector(changeMyFont:)];
[[NSFontManager sharedFontManager] setTarget:self]; //-- this seems to be not mandatory, but I mention it because your case could be different
I renamed changeFont: to changeMyFont::
- (void)changeMyFont:(id)sender
{
With these changes, the font is correctly updated in the example content view.
I don't know if it will work for you, because in the end you are trying to use this code in a different context, but I hope that it will. I would suggest you to first try and modify the sample project so that you can get confident with my solution and then move it to your project to check whether it also works there.