Custom Annotation View do not work on iOS6 - objective-c

I'm using the J4n0 Callout code (github) to implement a custom annotation in MapKit.
It was working just fine on iOS5. But on iOS6 I have 2 problems:
Annotations are displayed over the AnnotationView (see picture 1).
The first Click on an Annotation opens the AnnotationView just fine, but the second click opens an annotation with a bad size (see picture 2).
Does anyone using this library have some similar problem/solution?
I can give some code if needed!

If annotations are displayed over the AnnotationView try to code:
- (void)didMoveToSuperview {
[super didMoveToSuperview];
[self.superview bringSubviewToFront:self];
}
Just in case above solution doesn't work try
view.layer.zposition = 1

I am not sure whether you used the same code as mine, I downloaded it from somewhere to custom the annotationView and I also figured out that in the second time, the size is incorrect. I had noticed that the removeAnnotation function, will also make the annotationView call its didMoveToSuperview once again! Then I dug into the codes in didMoveToSuperview and found that the codes that I downloaded (i hope u meet the same one), do some animation in it so this will make the animation codes call twice. That makes the problem that "second click open an annotation with a bad size"
So remove this animation codes, or make it call somewhere else and NOT in didMoveToSuperview but properly. I hope this will help you, and hope you will share your advice if find out that I am wrong.

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.

ios7 mapview annotation button not showing

been googling this one for a good bit and i'm totally at a loss.
i'm porting to ios7 an app i built with a mapview with basic system annotations. everything is working great, the annotations are handling taps and acting as they're supposed to - but for some reason, there's no disclosure button appearing in the annotation. i haven't changed anything for prior ios7 releases and all the searching i've done has given me very little.
i've looked through changelogs and googled everything i can possibly come up with to solve this problem, and nothing has even remotely helped.
for my annotation view (which presented the old typical blue arrow button previously) i simply have …
UIButton* rightButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
which looks right and should be right (again, it's fine in ios6 and before) be for some reason, any sort of representation of a button is just not appearing.
thanks for any help here.
hahah oh jeez, this is why i shouldn't be working so late.
the default color of the disclosure button is apparently white. like the default annotation background color.
derp.
I had the same problem and hopefully this can help someone else looking here, I didn't seem to require this for the disclosure indicator to appear before iOS7, but I forgot to set the mapView delegate. Once I added this to the viewDidLoad, my indicators started to appear (even though the annotations were appearing without it):
mapView.delegate = self;

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.

Force the keyboard to become visible and stay visible in view

I want to have the virtual keyboard appear in my view on load and I want it to say visible for the lifetime of the view. There is a text field and I treat as the primary control for this view.
Initially, I called [self.textField becomeFirstResponder] in -viewWillAppear: following advice I've gotten here. Then, I came up with a different idea: I overloaded UIViewController's -becomeFirstResponder.
- (BOOL)becomeFirstResponder
{
if (self.primeResponder)
return [self.primeResponder becomeFirstResponder];
return [super becomeFirstResponder];
}
I'm not seeing any hidden problems with this, but then again, no one recommends it either. Am I missing something? Is this a bad approach? Please help.
In reviewing my old question, I thought now would be a good time provide an answer to this.
It works and does not have any major drawbacks.
I've had good luck with this method except in a peculiar circumstance. I used this to set a text field in a table view cell as the prime responder. In iOS 6, it didn't load the keyboard or highlight the textfield when the view was pushed onto the navigation controller stack.
See In iOS 6, -[UITextField becomeFirstResponder] doesn't work in -viewWillAppear: for my solution to that problem.

XCode 4. Keyboard doesn't hide on iPad

I have a problem with my iPad app.
I perform authorization in social networks (facebook, twitter etc.) to post information from app. Several webviews change each other (login, content of post, captcha). They have text fields and I have to show keyboard. After posting I return to some start view with posted information.
It works good, but after posting first news something goes wrong. When I post news one more time, after return keyboard is still on the screen.
I saw here some questions familiar to this, but they wasn't useful.
I tried to make resignFirstRersponder to all webViews, textFields and textViews. Also i\I tried to implement method disablesAutomaticKeyboardDismissal but it doesn't help me.
I don't know where search for problem...
So questions are: why could this happened? How can I solve this? fnd How can I get some information about keyboard? (is it visible, what object has focus etc., anything that could be useful to solve problem)
And one more thing. I have similar app for iPhone and it seems to work correct.
Try this:
[searchBar performSelector:#selector(resignFirstResponder) withObject:nil afterDelay:0.1];
Make sure to replace searchBar with the object that is the actual First responder in your case
Problem is fixed, finally. The reason was the way I had changed visible view. I set a new value to view property of ViewController. And as previous view contains text field with focus on it, focus wasn't lost before changing view (and keyboard was still on the screen), but I had lost handler to previous view.
Solution is: resignFirstResponder to all (or current) inputs BEFORE changing view.
Hope, it's clear. Thanks for your help!