Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-24-2009, 09:24 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
Default Custom keyboard with decimal point

Hey everyone,
I posted a thread on this the other day (http://www.iphonedevsdk.com/forum/ip...ng-string.html).

This time I'm including a few pictures to help explain the issue I'm having. The app I am creating uses multiple views and multiple text fields that use a custom number pad with a view added for a decimal point.

If I input a number with a decimal point once it works great, but if I click to another view and then go back to that text field to edit it with a different number the decimal point is then added twice. (see gif files attached)

The part of the code in the view controller that adds the decimal is:

- (void)addDecimal:(NSNotification *)notification {
textField1.text = [textField1.text stringByAppendingString:@"."];
}

I can post the rest of the code in the view controller and appDelegate if anyone thinks it will help.

Does anyone have any ideas? Let me know if I can post something else to clarify the question. I really appreciate anyone's help!
Attached Images
File Type: gif 1 decimal.gif (11.2 KB, 23 views)
File Type: gif 2 decimals.gif (11.1 KB, 16 views)
aaronsbush is offline   Reply With Quote
Old 03-24-2009, 12:36 PM   #2 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,178
Default

Quote:
Originally Posted by aaronsbush View Post
Hey everyone,
I posted a thread on this the other day (http://www.iphonedevsdk.com/forum/ip...ng-string.html).

This time I'm including a few pictures to help explain the issue I'm having. The app I am creating uses multiple views and multiple text fields that use a custom number pad with a view added for a decimal point.

If I input a number with a decimal point once it works great, but if I click to another view and then go back to that text field to edit it with a different number the decimal point is then added twice. (see gif files attached)

The part of the code in the view controller that adds the decimal is:

- (void)addDecimalNSNotification *)notification {
textField1.text = [textField1.text stringByAppendingString:@"."];
}

I can post the rest of the code in the view controller and appDelegate if anyone thinks it will help.

Does anyone have any ideas? Let me know if I can post something else to clarify the question. I really appreciate anyone's help!
It's impossible to tell based on what you've posted. It sounds like your addDecimal function may be called once more than you expect but, again, given what little you've posted, no one here can determine anything.
Kalimba is offline   Reply With Quote
Old 03-24-2009, 08:59 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
Default

Thanks Kalimba. Here is the code from the appDelegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

[window addSubview:navigationController.view];
[window addSubview:[rootViewController view]];
[window makeKeyAndVisible];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:optionsViewController selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];
}

- (void)keyboardWillShow:(NSNotification *)note {

UIWindow* tempWindow;
UIView* keyboard;
for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
{
tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];

if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
{
if (numberPadShowing) {
dot = [UIButton buttonWithType:UIButtonTypeCustom];
dot.frame = CGRectMake(0, 163, 106, 53);
[dot setImage:[UIImage imageNamed:@"dotNormal.png"] forState:UIControlStateNormal];
[dot setImage:[UIImage imageNamed:@"dotHighlighted.png"] forState:UIControlStateHighlighted];
[keyboard addSubview:dot];
[dot addTarget:self action:@selector(sendDecimal:) forControlEvents:UIControlEventTouchUpInside];

return;
}
}
}
}
}

- (void)sendDecimal:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"DecimalPressed" object:nil];
}



Here is the code from my viewController:

- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];
ProgramAppDelegate *programAppDelegate = (ProgramAppDelegate *)[[UIApplication sharedApplication] delegate];
programAppDelegate.numberPadShowing = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
ProgramAppDelegate *programAppDelegate = (ProgramAppDelegate *)[[UIApplication sharedApplication] delegate];
if (programAppDelegate.numberPadShowing) {
[programAppDelegate.dot removeFromSuperview];
}
programAppDelegate.numberPadShowing = NO;
}
- (void)addDecimal:(NSNotification *)notification {
textField1.text = [textField1.text stringByAppendingString:@"."];
}



Thanks again - any ideas or thoughts are appreciated!
aaronsbush is offline   Reply With Quote
Old 03-24-2009, 09:38 PM   #4 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,178
Default

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    [window addSubview:navigationController.view];
    [window addSubview:[rootViewController view]];
    [window makeKeyAndVisible];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:optionsViewController selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];
}

- (void)keyboardWillShow:(NSNotification *)note
{
    UIWindow* tempWindow;
    UIView* keyboard;
    for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
    {
        tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
        for(int i = 0; i < [tempWindow.subviews count]; i++)
        {
            keyboard = [tempWindow.subviews objectAtIndex:i];
			
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            {
                if (numberPadShowing)
                {
                    dot = [UIButton buttonWithType:UIButtonTypeCustom];
                    dot.frame = CGRectMake(0, 163, 106, 53);
                    [dot setImage:[UIImage imageNamed:@"dotNormal.png"] forState:UIControlStateNormal];
                    [dot setImage:[UIImage imageNamed:@"dotHighlighted.png"] forState:UIControlStateHighlighted];
                    [keyboard addSubview:dot];
                    [dot addTarget:self action:@selector(sendDecimal:)  forControlEvents:UIControlEventTouchUpInside];
					
                    return;					
                }
            }
        }
    }
}

- (void)sendDecimal:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"DecimalPressed" object:nil];	
}

Here is the code from my viewController:

- (void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addDecimal:) name:@"DecimalPressed" object:nil];
    ProgramAppDelegate *programAppDelegate = (ProgramAppDelegate *)[[UIApplication sharedApplication] delegate];
    programAppDelegate.numberPadShowing = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    ProgramAppDelegate *programAppDelegate = (ProgramAppDelegate *)[[UIApplication sharedApplication] delegate];
    if (programAppDelegate.numberPadShowing)
    {
        [programAppDelegate.dot removeFromSuperview];
    }	
    programAppDelegate.numberPadShowing = NO;
}

- (void)addDecimal:(NSNotification *)notification
{
    textField1.text = [textField1.text stringByAppendingString:@"."]; 
}
OK, let me first confess that I'm not familiar with some of the classes you're using in this code, but I get the gist of what you're doing here.

Having said that, I suspect that there may be a path through this code in which you're registering multiple observers for the same "DecimalPressed" event, and that's what is causing multiple decimal points to be added to your string. I don't see anything in the NSNotificationCenter docs indicating that registration of multiple identical observers is not allowed, so this theory is at least plausible. I would add breakpoints to the lines that add the observers to the notification center and see if you can find a case where this happens.
Kalimba is offline   Reply With Quote
Old 03-24-2009, 11:57 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
Default

Thanks again Kalimba. I'll try the break points and dig for multiple observers.
aaronsbush is offline   Reply With Quote
Old 03-25-2009, 12:32 AM   #6 (permalink)
iOS / MacOS Developer
 
bharath2020's Avatar
 
Join Date: Oct 2008
Location: Bengaluru
Posts: 150
Default

FYI.

I was just trying to add a custom over keyboard. With 2.2.1 SDK the UIKeyboard class has been changed to UITextEffectsWindow..
bharath2020 is offline   Reply With Quote
Old 03-30-2009, 09:58 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
Default

I finally figured out the issue. I did have too many observers or rather nothing to stop the observing. I had to separate the notification observers for each text field and then remove the observer as soon as the text editing stopped:

[[NSNotificationCenter defaultCenter] removeObserver:self];

Thanks again for all the ideas.
aaronsbush is offline   Reply With Quote
Reply

Bookmarks

Tags
append, custom keyboard, decimal point, notification, string

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 331
21 members and 310 guests
@sandris, ADY, BrianSlick, dacapo, Dani77, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, themathminister, timle8n1, tomtom100, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:09 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0