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

Reply
 
LinkBack Thread Tools Display Modes
Old 07-11-2011, 10:49 PM   #1 (permalink)
Tech Genius Developer
 
Join Date: Jul 2011
Posts: 40
vilisei is on a distinguished road
Send a message via Skype™ to vilisei
Default Keyboard Configurations/Problems

I am making a universal tabbed application, and one of the tabs is a login screen. How do I make the keyboard disappear when the user tabs outside the box or taps the sign in button? Also how do I link the next button to the password box as in when you type the username, there is a next button instead of a return button, but it won't go to the next field. I have tried other forums but they give me a stop sign (icon) error.
vilisei is offline   Reply With Quote
Old 07-11-2011, 11:15 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

1. David Linsin - Dismiss Keyboard on Tap "Outside"

2. Use the textfield delegate method, something like textFieldDidReturn. Make the second UITextfield the first responder and relieve the first one of its duties.
Domele is offline   Reply With Quote
Old 07-11-2011, 11:56 PM   #3 (permalink)
Tech Genius Developer
 
Join Date: Jul 2011
Posts: 40
vilisei is on a distinguished road
Send a message via Skype™ to vilisei
Default Problems

Where would I place that code? All I did was add a textfield (as in the picture) from the toolbox, I didn't write it in code. Here is all the code (except for the green stuff at the top):
PHP Code:
#import "FirstViewController.h"

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (
self) {
        
self.title NSLocalizedString(@"Account", @"Account");
        
self.tabBarItem.image = [UIImage imageNamed:@"first"];
    }
    return 
self;
}

- (
void)didReceiveMemoryWarning
{
    [
super didReceiveMemoryWarning];
    
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [
super viewDidLoad];
    
// Do any additional setup after loading the view, typically from a nib.
}

- (
void)viewDidUnload
{
    [
super viewDidUnload];
    
// Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (
void)viewWillAppear:(BOOL)animated
{
    [
super viewWillAppear:animated];
}

- (
void)viewDidAppear:(BOOL)animated
{
    [
super viewDidAppear:animated];
}

- (
void)viewWillDisappear:(BOOL)animated
{
    [
super viewWillDisappear:animated];
}

- (
void)viewDidDisappear:(BOOL)animated
{
    [
super viewDidDisappear:animated];
}

- (BOOL)
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    
// Return YES for supported orientations
    
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@
end 
Attached Images
File Type: jpg Screen Shot 2011-07-11 at 9.47.36 PM.jpg (13.9 KB, 5 views)
vilisei is offline   Reply With Quote
Old 07-12-2011, 12:34 AM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Just setup an IBOutlet and place the code in your .m file.
Domele is offline   Reply With Quote
Old 07-12-2011, 10:06 AM   #5 (permalink)
Tech Genius Developer
 
Join Date: Jul 2011
Posts: 40
vilisei is on a distinguished road
Send a message via Skype™ to vilisei
Default Placement

I still don't get it. Does it matter in what order to place it? Like before or after the (code below) or before/after what?
PHP Code:
#pragma mark - View lifecycle 
vilisei is offline   Reply With Quote
Old 07-12-2011, 10:16 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

Make IBOutlets for the text fields. then hook them up in IB. While in IB set the tag's of the text fields to 0 and 1 (you only have 2 fields right?) Then implement the textFieldShouldReturn method. That can be placed anywhere inside the .m for that view controller you want - it is a new method unto itself and doesnt need "calling" from elsewhere. In the method set an int to the textfield.tag and add 1 to it. Then an if statement to check when it has reached the highest tag it should return YES;.

For dismissing the keyboard on a click (i.e. background click) create an IBAction (i call mine background click :P) and in that method call "resignFirstResponder" on each of the text fields.

Post back if you need that clearing up a bit, rather not spoon feed the code if you can figure it out

Last edited by Meredi86; 07-12-2011 at 10:17 AM. Reason: changing a typo
Meredi86 is offline   Reply With Quote
Old 07-13-2011, 01:02 PM   #7 (permalink)
Tech Genius Developer
 
Join Date: Jul 2011
Posts: 40
vilisei is on a distinguished road
Send a message via Skype™ to vilisei
Default

What do you mean by IBOutlets? Is it like a new object or what? Also I am using Xcode 4 so I don't have Interface Builder.
vilisei is offline   Reply With Quote
Old 07-13-2011, 03:34 PM   #8 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Xcode 4 does have Interace Builder, it's just integrated into Xcode. IBOutlets are a way to reference objects built in Interface Builder. You declare them in your header file like so
Code:
IBOutlet UITextField *myTextField;
Then you go into Interface Builder, select the file owner, go to the last tab in properties, and click and drag the circle to the object.
Domele is offline   Reply With Quote
Old 07-15-2011, 02:45 PM   #9 (permalink)
Tech Genius Developer
 
Join Date: Jul 2011
Posts: 40
vilisei is on a distinguished road
Send a message via Skype™ to vilisei
Default

I found out how to make the keyboard disappear when you tap outside, but how do I make the next button link to the password box and the done button on the keyboard make the keyboard dissappear? Code for dismissing the keyboard when tapping outside:
PHP Code:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (
UIViewview in self.view.subviews)
    {
        if ([
view isKindOfClass:[UITextField class]]) {
            [
view resignFirstResponder];
        }
        
        if ([
view isKindOfClass:[UITextView class]]) {
            [
view resignFirstResponder];
        }
    }

vilisei is offline   Reply With Quote
Old 07-15-2011, 08:26 PM   #10 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 154
Bobarino is on a distinguished road
Default

Quote:
Originally Posted by vilisei View Post
I found out how to make the keyboard disappear when you tap outside, but how do I make the next button link to the password box and the done button on the keyboard make the keyboard dissappear? Code for dismissing the keyboard when tapping outside:
PHP Code:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (
UIViewview in self.view.subviews)
    {
        if ([
view isKindOfClass:[UITextField class]]) {
            [
view resignFirstResponder];
        }
        
        if ([
view isKindOfClass:[UITextView class]]) {
            [
view resignFirstResponder];
        }
    }

Dismissing keyboard with done button:

Code:
//in viewdidload

//Field is an IBOutlet
	
	Field.delegate = self;
	Field.returnKeyType = UIReturnKeyDone;
Code:
- (BOOL)textFieldShouldReturn:(UITextField *)field {
	[field resignFirstResponder];
	return YES;
Bobarino is offline   Reply With Quote
Reply

Bookmarks

Tags
ipad, iphone, xcode 4

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: 369
9 members and 360 guests
apatsufas, chemistry, Kirkout, leostc, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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