Strange issue with numeric keyboard losing custom UIButton when it finishes displaying - iphone

As hacky as it seems, I am using this method to add a done button to my numeric keyboard:
UIKeyboardTypeNumberPad without a done button
I toggle the slow animation and it looks like this while it is still animating and not quite done:
But then, when it finishes loading, it looks like this!
The UIButton I am adding just disappears! I subscribed to UIKeyboardDidShowNotification and filter through the subviews and can see that by the time the notification is fired, there is no longer a UIButton as a subview of the keyboard.
I tried turning off ARC for the file but still no luck.
Any ideas as to what might be causing the UIButton to vanish? The button is a STRONG property btw.
Thanks

please, can you check again, maybe you have omitted something.. https://dl.dropbox.com/u/19438780/KeyboardExtension.zip
Another tutorial/example for iOS6: http://ofanyuse.wordpress.com/2012/11/09/an-elegant-solution-to-adding-a-uibutton-to-the-numberpad/

Related

touchesBegan not called on UITextField

I have created a simple test project with a single UITextView and the touchesBegan method in the view controller. For some reason, the UITextView is not responding to touchesBegan.
Things I have tried:
Alpha is set to 1
User interaction is enabled on the view and the UITextView
Delay Touch Down is unchecked
The background is set to a solid color
I found similar questions in several places, but none of the solutions have worked.
While it seems like others have successfully gotten touchesBegan to work on a UITextField in the past, nothing seems to be working now. Instead, I simply added textFieldDidBeginEditing and canceled the animation from there. Problem solved.

dismiss the UIKeyboardTypeDecimalPad in UIScrollView background

I am dealing with what seems to be a somewhat rudimentary problem. I am trying to dismiss a UIKeyboardTypeDecimalPad that has a UIScrollView background. I have seen some solutions that involve putting a done button where the decimal is if you have just a NumberPad. The problem is, I really need a decimal.
My next thought was to dismiss the keypad when the user touches the background, but since the background is a scroll view, I couldn't seem to connect an action to pick up a touch? One solution was to perhaps created a Custom Scroll View Controller...all of this seems a bit messy just to dismiss a keypad. Do I really have to do this?
Would it work for you if you put a UIBarButtonItem "Done" in your navigation bar?
Have you explored the UITextField property inputAccessoryView?

IPhone UIButton doesn't respond in a UIScrollView

I'm an iPhone dev newbie, and I'm having a problem slightly similar to a few posts I read around here, but none of them seemed to help.
I have created a UIScrollView, with a UIView as its content (a subview). During runtime, the UIView is populated with labels and buttons. Everything looks fine, scrolling works perfectly, but the UIButtons never fire when pressed, no matter what I do. I've tried many combinations of properties suggested here, to the best of my understanding, but still nothing worked. I'm afraid I might have misunderstood something about the mechanism.
I should mention that everything is done in code (no IB).
Any suggestions?
My bug (written in the comments of my question) was not setting the frame of the contentview that was the parent of all buttons. The result was strange - I could see the button subviews (which was why it took me a while to find the bug) but could not click on them. oops!
This also may happen, when your custom UIView userInteractionEnabled is NO (default is NO).
try [btn becomeFirstResponder];

UICatalog and Keyboard Events

The latest version of Apple's UICatalog example application includes zero code in the TextFieldController for handling keyboard show/hide events, and yet the table view still slides up and down beautifully with the keyboard.
Does anyone know what the new trick is? Are there settings in the XIB that allowed them to forgo registering for the notifications or using TextField delegate methods?
The TextViewController still uses keyboard notifications to deal with view sliding, so I'm really confused as to why this isn't included for TextFields anymore.
Thoughts?
You can close the keyboard, if it's open by calling:
[sender resignFirstResponder];
Not sure about opening the keyboard however.
The trick is hidden within calling becomeFirstResponder on a UITextField that is in a scrollable view. Apparently, whenever calling [textField becomeFirstResponder], iOS automatically scrolls the parent view until said textField is visible.
This behavior can actually be undesirable in some cases, as it will not usually scroll to the same location that the UIScrollView method scrollRectToVisible:animated: would if you were to try to do things that way.
Thanks for your thoughts everyone!

UIButton delayed state change

I have a UIButton subview inside of a UITableViewCell.
When this button is touched, the user must hold the button for about a half second for the button's image to change to the UIControlStateHighlighted image.
This means that if the user just taps the button as is usually the case, the highlighted state is never shown.
Why does this occur and how can I fix it?
I just encountered this problem and saw that this issue hadn't been closed. After screwing around for a while I found a fix for it.
Now you can fix this by turning off delaysContentTouches or unchecking the "Delays content touches" box on the tableview.
The only negative side effect is that the user won't be able to tap down on a button and initiate a scrolling gesture. However, if the user tries to scroll starting from anywhere that doesn't itself accept touches, the behavior should be the same as before.
The problem is that your UIButton is inside a UITableView. This means that the table view has to determine whether your tap is going to be a swipe or if it's just a tap intended for the button. The table view has to delay sending a message to the UIButton until it knows that the user doesn't intend to swipe and therefore scroll the view instead of pressing the button.
If you don't need a table view, get rid of the UITableView.
Up for David Hodge's answer.
I just want to add a way to remove that "only negative side effect", already described by David: if you start scrolling inside a UIcontrol in a UIScrollView with delayContentTouches=NO, scrolling doesn't work.
SOLUTION
Subclass UIScrollView (or UITableView as the original question) and override:
-(BOOL) touchesShouldCancelInContentView:(UIView *)view {
return YES;
}
Your UIControls inside UIScrollView/UITableView will change their state immediately on tap and the scrollviews will be able to scroll even if the touch starts on some UIControl. Works like a charm.
I just change the image from within the target action method:
[sender setBackgroundImage:[UIImage imageNamed:#"highlighted-image.png"] forState:UIControlStateNormal];
It changes the background image instantly.
Edit: completely re-written following a misunderstanding of the question
One way of thinking of a UIButton is as a shorthand way of setting up an area of the screen that can respond to various instantaneous touch events the response it makes is defined by UIControl's Target-Action system for delivering messages to other objects.
UIControlEventTouchDown sounds like the one you need to respond to. It will be triggered as soon as someone touches inside your button - this is what the "Contact Info" button in SMS does.
UIButton* myButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect];
// SEt up title, frame etc
[myButton addTarget:self action:#selector(myButtonWasPressed) forControlEvents: UIControlEventTouchDown];
[myMainView addSubView:myButton];
Will send a -(void)myButtonWasPressed message to the object this code runs from (ideally you view controller). In myButtonWasPressed you can then add a new view or take any action you like. The SMS app pushes a view controller to display the contact info using a navigation controller.
If this still doesn't solve your problem, you're going to have to post some code in order to get more insight into what's going wrong.