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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 05-14-2011, 03:09 PM   #1 (permalink)
Registered Member
 
ManWithMask's Avatar
 
Join Date: Mar 2010
Location: Stellenbosch, South Africa
Posts: 88
ManWithMask is on a distinguished road
Send a message via Skype™ to ManWithMask
Question NSNotification - keyboard

I'm adding the Done button to the Num pad using NSNotifications keyboard observer.

It however does not always work in all cases:

1. User click on the DONE buttons for either pad to close that pad each time they move from field to field, then it works 100%.

2. User clicks on the next field without first clicking on the DONE button, then the NSNotification will not observe any keyboard changes and so the keyboard observers will not work.


I would appreciate anyone who has a solution to this as it will help a lot of people struggling with the Done button added to the num pad.

I am attaching the complete code. It will help if you can review that and see what can be done. If we can get working, then I will post the code for all.

Thanks ahead!
Attached Files
File Type: zip Done.zip (94.5 KB, 5 views)
__________________
iPhone Apps: Who SAid™, iFRICA™, iFA™, iReceipt™,eCash™
ManWithMask is offline   Reply With Quote
Old 05-15-2011, 05:03 AM   #2 (permalink)
Registered Member
 
ManWithMask's Avatar
 
Join Date: Mar 2010
Location: Stellenbosch, South Africa
Posts: 88
ManWithMask is on a distinguished road
Send a message via Skype™ to ManWithMask
Unhappy DONE button display persists on default pad

Quote:
Originally Posted by ManWithMask View Post
I'm adding the Done button to the Num pad using NSNotifications keyboard observer.

It however does not always work in all cases:

1. User click on the DONE buttons for either pad to close that pad each time they move from field to field, then it works 100%.

2. User clicks on the next field without first clicking on the DONE button, then the NSNotification will not observe any keyboard changes and so the keyboard observers will not work and the DONE button display persists on default pad.

I would appreciate anyone who has a solution to this as it will help a lot of people struggling with the Done button added to the num pad.

I am attaching the complete code. It will help if you can review that and see what can be done. If we can get working, then I will post the code for all.

Thanks ahead!
Here is the ViewController code:

Code:
@implementation DoneViewController

@synthesize mynumberField,mytextField,addDone,doneButton; 


- (void)viewDidLoad
{
	[super viewDidLoad];
	
	//Add observers for the respective notifications (depending on the os version)
	if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
		[[NSNotificationCenter defaultCenter] addObserver:self 
												 selector:@selector(keyboardDidShow:) 
													 name:UIKeyboardDidShowNotification 
												   object:nil];	

	} else {
		[[NSNotificationCenter defaultCenter] addObserver:self 
												 selector:@selector(keyboardWillShow:) 
													 name:UIKeyboardWillShowNotification 
												   object:nil];
	}
    
}
#pragma mark -
#pragma mark DONE button for Numeric Keypad
- (void)keyboardWillShow: (NSNotification *)notification {
	//Num pad - add Num Pad
	NSLog(@"addDone: %@\n", (addDone ? @"YES" : @"NO"));
	if (addDone == YES) {
		if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2) {
			[self performSelector:@selector(addHideKeyboardButtonToKeyboard) withObject:nil afterDelay:0];
		}
	}
	
}
- (void)keyboardDidShow:(NSNotification *)notification {
	//Num pad - add Num Pad
	NSLog(@"addDone: %@\n", (addDone ? @"YES" : @"NO"));
	if (addDone == YES) {
		if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
			[self performSelector:@selector(addHideKeyboardButtonToKeyboard) withObject:nil afterDelay:0];
		}
	}
}
- (void)addHideKeyboardButtonToKeyboard {
	UIWindow *keyboardWindow = nil;
	for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
		if (![[testWindow class] isEqual:[UIWindow class]]) {
			keyboardWindow = testWindow;
			break;
		}
	}
	if (!keyboardWindow) return;
	
	// Locate UIKeyboard.  
	UIView *foundKeyboard = nil;
	for (UIView *possibleKeyboard in [keyboardWindow subviews]) {
		
		// iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
		if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
			possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
		}                                                                                
		
		if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
			foundKeyboard = possibleKeyboard;
			break;
		}
	}
	
	if (foundKeyboard) {
		
		[self addButtonToKeyboard];
		
	}
}
-(void)addButtonToKeyboard {
	// create custom button
	doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
	doneButton.frame = CGRectMake(0, 163, 106, 53);
	doneButton.adjustsImageWhenHighlighted = NO;
	if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
		[doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
		[doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
	} else {        
		[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
		[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
	}
	[doneButton addTarget:self action:@selector(removeNumberKeyboard:) forControlEvents:UIControlEventTouchUpInside];
	// locate keyboard view
	UIView *keyboard;
	UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
	for(int i=0; i<[tempWindow.subviews count]; i++) {
		keyboard = [tempWindow.subviews objectAtIndex:i];
		// keyboard found, add the button
		if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
			if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
				[keyboard addSubview:doneButton];
		} else {
			if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
				[keyboard addSubview:doneButton];
		}
	}
}
//Remove Number keyboard when you press DONE button
-(void)removeNumberKeyboard:(id)sender {
    [self.view endEditing:TRUE];
}
//Remove Default keyboard when you press DONE button
-(IBAction)closeDefaultKeyBoard {

}
#pragma mark -
#pragma mark UITextFieldDelegate methods
- (void)textFieldDidBeginEditing:(UITextField *)textField {
	//if editing textfields, then do not add DONE button
	if (mytextField.editing) {
		addDone = NO;
	}else{
		addDone = YES;
	}
	NSLog(@"addDone: %@\n", (addDone ? @"YES" : @"NO"));
}
#pragma mark -
#pragma mark Other Lifecycle
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc
{
    [super dealloc];
	[mynumberField release];
	[mytextField release];
	[doneButton release];
}
- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
@end
__________________
iPhone Apps: Who SAid™, iFRICA™, iFA™, iReceipt™,eCash™
ManWithMask is offline   Reply With Quote
Old 05-15-2011, 11:43 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you don't need to create multiple threads for the same problem, you created 3 threads for that....

http://www.iphonedevsdk.com/forum/ip...tml#post334942
__________________
dany_dev is offline   Reply With Quote
Old 05-15-2011, 12:03 PM   #4 (permalink)
Registered Member
 
ManWithMask's Avatar
 
Join Date: Mar 2010
Location: Stellenbosch, South Africa
Posts: 88
ManWithMask is on a distinguished road
Send a message via Skype™ to ManWithMask
Default

Quote:
Originally Posted by dany_dev View Post
you don't need to create multiple threads for the same problem, you created 3 threads for that....

http://www.iphonedevsdk.com/forum/ip...tml#post334942
I realize...just was not getting any bites. Sorry!
__________________
iPhone Apps: Who SAid™, iFRICA™, iFA™, iReceipt™,eCash™
ManWithMask is offline   Reply With Quote
Reply

Bookmarks

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: 396
19 members and 377 guests
Absentia, AyClass, baja_yu, checkright, Diligent, dre, fvisticot, givensur, jbro, jPuzzle, momolgtm, Newbie123, Punkjumper, revg, sacha1996, skrew88, taylor202, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,858
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

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