Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
So for my application I needed to add a button to the number pad keyboard because I wanted users to be able to enter decimal values but the standard button keyboard doesnt include the decimal. And using a full keyboard has a lot of wasted keys that I had to restrict the user from hitting.
Then I came across this post that discussed the issue somewhat.
I wanted to elaborate on that post to show how I was able to actually access the view of the keyboard to add my own buttons.
Step 1: Follow the instructions in the above post to handle the messages sent when the the keyboard is going to be show/hidden. This will help you understand a little more about how the keyboard works.
For my use I didnt really need to know the information regarding position of the keyboard and all that, but it was handy to know when it is being show.
Step 2: Check out the code below that actually gets you a reference to the UIKeyboard view (UIView) which will allow you to add subviews.
//The UIWindow that contains the keyboard view - It some situations it will be better to actually //iterate through each window to figure out where the keyboard is, but In my applications case //I know that the second window has the keyboard so I just reference it directly UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
//Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. //UIKeyboard is a subclass of UIView anyways UIView* keyboard;
//Iterate though each view inside of the selected Window for(int i = 0; i < [tempWindow.subviews count]; i++) { //Get a reference of the current view keyboard = [tempWindow.subviews objectAtIndex:i];
//Check to see if the className of the view we have referenced is \"UIKeyboard\" if so then we found //the keyboard view that we were looking for if([[keyboard className] isEqualToString:@\"UIKeyboard\"] == YES) { //Keyboard is now a UIView reference to the UIKeyboard we want. From here we can add a subview //to th keyboard like a new button
//Do what ever you want to do to your keyboard here... } }
I put the above code inside of the appDelegate into a method that I call the first time that the user shows the textbox (figured that out using the didShow method in step1).
Im not much of a tutorial writter, but hopefully that will shine some light on how to add custom items to your keyboards :)
Apparently className does not work with the 2.1 firmware or in all conditions so as per the article linked above I would recomend a change in the code i provided.
Thanks for the good responses. When I get some time I will write a proper tutorial with images and put it in the tutorial section. Just trying to finished up my first app for now :)
I have not used your technique, but I think the following is safer using isKindOfClass. It allows my code to detect my IB changes "cleanly" when I forget to make all the code changes.
#define TAG_MYBUTTON (1234) /* Set the tag in IB */ . . assert([[self viewWithTag:TAG_MYBUTTON] isKindOfClass:[UIButton class]]); UIButton *buttonMyButton = (UIButton*) [self viewWithTag:TAG_MYBUTTON]; assert(buttonMyButton);
so, extending to your example:
if( [keyboard isKindOfClass: [UIKeyboard class]] ) { // ... use the keyboard }
Give it a try and some thought, you might find it preferable.
thanks for all the above info, its set me on my way to adding a decimal point in the number pad.
one thing that's still puzzling me though. If I have the keyboard set to emoji,(by this I mean that the last view the keyboard was showing before being dismissed was the emoji one) and I pop my viewController that shows the keyboard with added decimal point subview, the keyboard that is shown is the emoji one? I have to go into another view and change it, as the decimal place subview hides the international keyboard symbol.
any ideas on how I would tailor this line: if([[keyboard description] hasPrefix:@" to show the number pad only?
The custom button does not produce the standard click. Is there a way to use the standard sound or I have to create my own click.caf and play it when the custom button is clicked ?
The custom button does not produce the standard click. Is there a way to use the standard sound or I have to create my own click.caf and play it when the custom button is clicked ?
I have figured out how to do that. I grabbed the default sound from the iphone. It's Tack.caf. And created the system sound which is played when the button is clicked.
Allthough you might want to add this in the if else clause...
//Also check if button has not already been added otherwise it will be added over and over again each time you switch edits. if (numberPadShowing && [keyboard viewWithTag:123] == nil)
//Only remove if the number pad is not showing, otherwise it will switch between adding it and removing it with every begin edit. else if (!numberPadShowing) {
for (UIView *v in [keyboard subviews]){ if ([v tag]==123) [v removeFromSuperview]; } }
The reason the other code works is because the foreach loop will still remove every single subview that was added. However this consumes resources and time.
I just wanted to get rid of the keyboard without pressing [search]. So I found it easier to add a gesture tap recogniser to the view behind the search bar. This seems to be what most other apps do. Don't know if there are any catches to doing it this way! //link Sent actions to gesture tap recogniser in IB - (IBAction)tapGesture: (id)sender { NSLog(@"tapGesture"); if (self.userSearchBar != nil){ [self.userSearchBar resignFirstResponder]; } } // add UISearchBarDelegate to UIViewController //add to UIViewCnt?.h IBOutlet UISearchBar *userSearchBar; //@property (strong, nonatomic) IBOutlet UISearchBar *userSearchBar;
I just wanted to get rid of the keyboard without pressing [search]. So I found it easier to add a gesture tap recogniser to the view behind the search bar. This seems to be what most other apps do. Don't know if there are any catches to doing it this way! //link Sent actions to gesture tap recogniser in IB - (IBAction)tapGesture: (id)sender { NSLog(@"tapGesture"); if (self.userSearchBar != nil){ [self.userSearchBar resignFirstResponder]; } } // add UISearchBarDelegate to UIViewController //add to UIViewCnt?.h IBOutlet UISearchBar *userSearchBar; //@property (strong, nonatomic) IBOutlet UISearchBar *userSearchBar;
Replies
Apparently className does not work with the 2.1 firmware or in all conditions so as per the article linked above I would recomend a change in the code i provided.
that if statement should change. Instead of using [keyboard className] I used the following line of code
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome#define TAG_MYBUTTON (1234) /* Set the tag in IB */
.
.
assert([[self viewWithTag:TAG_MYBUTTON] isKindOfClass:[UIButton class]]);
UIButton *buttonMyButton = (UIButton*) [self viewWithTag:TAG_MYBUTTON];
assert(buttonMyButton);
so, extending to your example:
if( [keyboard isKindOfClass: [UIKeyboard class]] ) {
// ... use the keyboard
}
Give it a try and some thought, you might find it preferable.
-m2c
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeone thing that's still puzzling me though. If I have the keyboard set to emoji,(by this I mean that the last view the keyboard was showing before being dismissed was the emoji one) and I pop my viewController that shows the keyboard with added decimal point subview, the keyboard that is shown is the emoji one? I have to go into another view and change it, as the decimal place subview hides the international keyboard symbol.
any ideas on how I would tailor this line:
if([[keyboard description] hasPrefix:@"
to show the number pad only?
many thanks
Nik
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeif([[keyboard description] hasPrefix:@"
not as my mac during the day, so doing my usual of asking before I've really thought it through ;-)
cheers
Nik
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeFor me, it seems that no matter what type of keyboardType is being used, it will always return UIKeyboard.
I can't seem to find a way to distinguish between what kind of keyboard is currently being used - anyone know something that I don't?
Thanks!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=29756204
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAllthough you might want to add this in the if else clause...
//Also check if button has not already been added otherwise it will be added over and over again each time you switch edits.
if (numberPadShowing && [keyboard viewWithTag:123] == nil)
//Only remove if the number pad is not showing, otherwise it will switch between adding it and removing it with every begin edit.
else if (!numberPadShowing)
{
for (UIView *v in [keyboard subviews]){
if ([v tag]==123)
[v removeFromSuperview];
}
}
The reason the other code works is because the foreach loop will still remove every single subview that was added. However this consumes resources and time.
Hope this helps =)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome1) I've heard that some methods of messing with the keyboard will get your app rejected; is this one kosher?
2) Do any of you have a sample project of a custom keyboard set up somewhere? Saving time is always good ;) Thanks!
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis seems to be what most other apps do. Don't know if there are any catches to doing it this way!
//link Sent actions to gesture tap recogniser in IB
- (IBAction)tapGesture: (id)sender {
NSLog(@"tapGesture");
if (self.userSearchBar != nil){
[self.userSearchBar resignFirstResponder];
}
}
// add UISearchBarDelegate to UIViewController
//add to UIViewCnt?.h IBOutlet UISearchBar *userSearchBar;
//@property (strong, nonatomic) IBOutlet UISearchBar *userSearchBar;
- (void) searchBarTextDidBeginEditing: (UISearchBar *)searchBar{
self.userSearchBar = searchBar;
NSLog(@"search begin edit");
}
- (void)searchBarSearchButtonClicked: (UISearchBar *)searchBar{
[searchBar resignFirstResponder];
self.userSearchBar = searchBar;
NSString *searchFor = self.userSearchBar.text;
NSLog(@"user searched %@",searchFor);
self.userSearchBar = nil;
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeCan any one help me how to play play radio in BAckground..
Thankx IN advance
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome