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 08-22-2008, 03:05 PM   #1 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default How to hide keyboard when you press the button

does anyone knows how to hide keyboard when you click a button?
jessesar is offline   Reply With Quote
Old 08-22-2008, 03:12 PM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

Code:
- (BOOL)textFielsShouldReturn:(UITextField *)textField {
  [textField] resignFirstResponder];
  return YES;
bikr is offline   Reply With Quote
Old 08-22-2008, 03:16 PM   #3 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default

where should i place it?
jessesar is offline   Reply With Quote
Old 08-22-2008, 03:19 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

In your view.m where the text entry is located somewhere at the bottom probably out of the way but before the @end
bikr is offline   Reply With Quote
Old 08-22-2008, 03:26 PM   #5 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default

then i get 2 errors and 1 warning
jessesar is offline   Reply With Quote
Old 08-22-2008, 03:27 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

what are they? Post your entire code between code brackets [ code ] code goes here [ /code ]
bikr is offline   Reply With Quote
Old 08-22-2008, 03:34 PM   #7 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default

i am practicing with textfields, just for practice:

Code:
#import "lockerViewController.h"

@implementation lockerViewController
- (IBAction)lock {
// Actions etc..
}
@end
when you press the button the lock action will be called.
this is just for practice
the textField is called codeField
jessesar is offline   Reply With Quote
Old 08-22-2008, 03:50 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

Basically..
Code:
#import "lockerViewController.h"

@implementation lockerViewController
- (IBAction)lock {
// Actions etc..
}

- (BOOL)textFielsShouldReturn:(UITextField *)textField {
  [textField] resignFirstResponder];
  return YES;
}

@end
bikr is offline   Reply With Quote
Old 08-22-2008, 03:57 PM   #9 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default

no, then i keep getting errors

but
Code:
textFielsShouldReturn
maybe this should be:
Code:
textFieldShouldReturn
?
jessesar is offline   Reply With Quote
Old 08-22-2008, 04:01 PM   #10 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

yah, typo on my part.. should be as you typed.
bikr is offline   Reply With Quote
Old 08-22-2008, 04:03 PM   #11 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default

that don't work also
jessesar is offline   Reply With Quote
Old 08-22-2008, 04:26 PM   #12 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

ok , well that's how you do it directly form the documentation copy and pasted.. So.. problem must lie elsewhere.. did you create the outlets and declare them in your .h?
bikr is offline   Reply With Quote
Old 08-23-2008, 04:23 AM   #13 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 16
Default

this is lockerViewController.h:

Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface lockerViewController : UIViewController {
    IBOutlet UITextField *codeField;
}
- (IBAction)lock;
@end
and this is lockerViewController.m:

Code:
#import "lockerViewController.h"

@implementation lockerViewController
- (IBAction)lock {
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField] resignFirstResponder];
	return YES;
}

@end
jessesar is offline   Reply With Quote
Old 08-23-2008, 08:01 AM   #14 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 272
Default

I'm pretty sure you want it in the view class not the controller but you got me
bikr is offline   Reply With Quote
Old 09-19-2008, 07:30 AM   #15 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 20
Default

Quote:
Originally Posted by bikr View Post
I'm pretty sure you want it in the view class not the controller but you got me
Yes, same problem for me. It works when implemented in the view class, but I need it to execute a method from the controller. Please someone with an idea?
Gero is offline   Reply With Quote
Old 10-02-2008, 07:12 AM   #16 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 2
Default

To hide a keyboard u need just to setup a callback (i.e. IBAction) for the event "Did End On Exit" of UITextField in the InterfaceBuilder. So make ur UITextField an IBOutlet and put an empty IBAction as a callback for "Did End On Exit". That's all.

Like this:

//header

@interface MyView : UIView
{
IBOutlet UITextField *name;
}

- (IBAction)doneButtonOnKeyboardPressed: (id)sender;

//m-file

@implementation MyView

- (IBAction)doneButtonOnKeyboardPressed: (id)sender
{}

@end
incorrect.user is offline   Reply With Quote
Old 02-06-2009, 04:24 AM   #17 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 3
Default Can Somebody tell me how to dismiss keyboard on click of UITextField

Can Somebody tell me how to dismiss keyboard on click of UITextField which i created in interface builder because i want to select data from the UIPickerView to fill the UITextField instead of typing the text from the keyboard



Quote:
Originally Posted by incorrect.user View Post
To hide a keyboard u need just to setup a callback (i.e. IBAction) for the event "Did End On Exit" of UITextField in the InterfaceBuilder. So make ur UITextField an IBOutlet and put an empty IBAction as a callback for "Did End On Exit". That's all.

Like this:

//header

@interface MyView : UIView
{
IBOutlet UITextField *name;
}

- (IBAction)doneButtonOnKeyboardPressed: (id)sender;

//m-file

@implementation MyView

- (IBAction)doneButtonOnKeyboardPressed: (id)sender
{}

@end
nirmala1982 is offline   Reply With Quote
Old 02-09-2009, 01:32 AM   #18 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 3
Default Can Somebody tell me how to dismiss keyboard on click of UITextField

Can Somebody tell me how to dismiss keyboard on click of UITextField which i created in interface builder because i want to select data from the UIPickerView to fill the UITextField instead of typing the text from the keyboard
nirmala1982 is offline   Reply With Quote
Old 02-09-2009, 04:21 AM   #19 (permalink)
nikvpat
 
nikvpat's Avatar
 
Join Date: Jan 2009
Location: India
Age: 25
Posts: 104
Default

Quote:
Originally Posted by nirmala1982 View Post
Can Somebody tell me how to dismiss keyboard on click of UITextField which i created in interface builder because i want to select data from the UIPickerView to fill the UITextField instead of typing the text from the keyboard


There is an attribute editable for text field which can be set through attribute inspector

deselect this attribute

this will make sure that text inside text field can not be modified by user.

hence key board will not appear.............

happy coding
__________________
nikvpat
nikvpat is offline   Reply With Quote
Old 02-09-2009, 06:11 AM   #20 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 3
Default I dont see attribute editable for the text field

Hi nikvpat,

I have created UIPickerView using interface builder and i want to load this when the user clicks on UITextField, every time i click on UiTextField Keyboard pops up but i dont see UIPickerView loading from NSBundle can help me on this

Thanks in advance
nirmala1982 is offline   Reply With Quote
Old 02-09-2009, 08:36 AM   #21 (permalink)
Registered Member
 
kilobytedump's Avatar
 
Join Date: Oct 2008
Posts: 195
Default

Quote:
Originally Posted by nirmala1982 View Post
Hi nikvpat,

I have created UIPickerView using interface builder and i want to load this when the user clicks on UITextField, every time i click on UiTextField Keyboard pops up but i dont see UIPickerView loading from NSBundle can help me on this

Thanks in advance
I simply point the Did End On Exit to a dummy piece of code.

Dismisses the keyboard just fine.
kilobytedump is offline   Reply With Quote
Old 02-09-2009, 11:26 PM   #22 (permalink)
nikvpat
 
nikvpat's Avatar
 
Join Date: Jan 2009
Location: India
Age: 25
Posts: 104
Default

Quote:
Originally Posted by nirmala1982 View Post
Hi nikvpat,

I have created UIPickerView using interface builder and i want to load this when the user clicks on UITextField, every time i click on UiTextField Keyboard pops up but i dont see UIPickerView loading from NSBundle can help me on this

Thanks in advance

Refer methods of text field delegate in Apple Doc.....

find out method which causes keyboard to pop up.

in that method you can load UIPickerView from NIB file.

happy coding...............
__________________
nikvpat
nikvpat is offline   Reply With Quote
Old 03-27-2009, 08:04 AM   #23 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 5
Default

I try to repeat example into First Steps manual, but i can't understand how to hide keyboard when you press the button Done.
here is my code in "MyViewController.h"


Quote:
#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
}

@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction)changeGreeting:(id)sender;
@end
and "MyViewController.m"

Quote:
#import "MyViewController.h"

@implementation MyViewController
@synthesize textField;
@synthesize label;
@synthesize string;
- (IBAction)changeGreeting:(id)sender {
self.string = textField.text;
NSString *nameString = string;
if ([nameString length] == 0) {
nameString = @"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!",nameString];
label.text = greeting;

[greeting release];
}

-(BOOL)textFieldShouldReturn:(UITextField *)Done {
[Done resignFirstResponder];
return YES;
}
where is mistake ? keyboard doesn't hide.
kaktusok is offline   Reply With Quote
Old 03-27-2009, 10:04 AM   #24 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: the Netherlands
Posts: 19
Send a message via MSN to Malork
Default

make these changes in your .H-file:

Quote:
#import <UIKit/UIKit.h>


@interface MyViewController : UIViewController {
UITextField *textField;
UILabel *label;
NSString *string;
}

@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction)changeGreeting: (id)sender;
- (IBAction)dismissKeyboard: (id)sender;

@end
and in your .m-file:

Quote:

#import "MyViewController.h"

@implementation MyViewController
@synthesize textField;
@synthesize label;
@synthesize string;
- (IBAction)changeGreeting: (id)sender {
self.string = textField.text;
NSString *nameString = string;
if ([nameString length] == 0) {
nameString = @"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!",nameString];
label.text = greeting;

[greeting release];
}

-(IBAction)dismissKeyboard: (id)sender {
[sender resignFirstResponder];
}
then, connect in the IB's inspector for the textfield the 'did end on exit' option and connect it to the 'dismissKeyboard'.

Also, I believe it's also possible to do it with a delegate so you do not need to connect anything, but I'm not sure and have to look that one up.
(I think it had something to do with the <UIApplicationDelegate> protocol....)
But don't take my word for that one....yet..
Malork is offline   Reply With Quote
Old 03-27-2009, 10:22 AM   #25 (permalink)
1026 Development
 
Join Date: Jul 2008
Age: 23
Posts: 1,088
Send a message via AIM to Jeremy1026
Default

To use the code initially posted you have to make the textfield delegate self for the textfield that is currently the first responder..
Jeremy1026 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: 446
10 members and 436 guests
banatary70, darbsllim, DaveDee, EdwardMichel, ilmman, iOSguru, johnRambo, maryrobertson, Objective Zero, Oral B
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 157,853
Threads: 88,914
Posts: 379,297
Top Poster: BrianSlick (7,072)
Welcome to our newest member, banatary70
Powered by vBadvanced CMPS v3.1.0

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