Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

drf1229

macrumors regular
Original poster
Jun 22, 2009
237
0
I am making a program that requires the user to submit some input. I have a submit button, three text fields, and an IBAction. How do I make the action run when the user presses enter on the keyboard? Any help will do, I'm a beginner at iphone development.
 
Yes, but I have no idea how to do that. I also want the keyboard to hide when the action starts. (I'm still working on the same project as the last post btw)
 
Yes, but I have no idea how to do that. I also want the keyboard to hide when the action starts. (I'm still working on the same project as the last post btw)
I believe you'll need to do these things programatically (vs. thru IB). Look into using resignFirstResponder to hide the keyboard. The same place you do that, you probably can also call your IBAction method.
 
Actually, I'm still a bit confused...
I did this:

Code:
[C resignFirstResponder]

But that does nothing... What exactly does resignFirstResponder do?
 
Actually, I'm still a bit confused...
I did this:

Code:
[C resignFirstResponder]

But that does nothing... What exactly does resignFirstResponder do?

resignFirstResponder resigns the first responder status of the text field, making the keyboard disappear.
 
Code:
//
//  ViewController.m
//  PercentFinder
//
//  Created by Danny Flax on 6/21/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"
#import <stdio.h>
#import "PercentFinderAppDelegate.h"
@implementation MyViewController
@synthesize C;







-(IBAction)Solve:(UIButton*)sender{
	
	[C resignFirstResponder];
	
		NSString*as=[A text];
	float a=[as intValue];
	NSString*bs=[B text];
	float b=[bs intValue];
	NSString*cs=[C text];
	float c=[cs intValue];
	float d=((-1*b)+sqrt((b*b)-4*(a*c)))/(2*a);
	float e=((-1*b)-sqrt((b*b)-4*(a*c)))/(2*a);
	printf("%f and %f\n",d,e);
	 
	
	[Answer setText:[NSString stringWithFormat:@"%f and %f",d,e]];
		
		

	
	
	
}


@end
 
Guess what, I googled, and I figured it out! I now know how to execute events when enter is pressed on the keyboard. Thank you for your help still! I have one more question though. How do I shift focus from one textfield to another? In other words, when somebody presses enter in the A textfield, I want the focus to go to B, and so on.
 
Guess what, I googled, and I figured it out! I now know how to execute events when enter is pressed on the keyboard. Thank you for your help still! I have one more question though. How do I shift focus from one textfield to another? In other words, when somebody presses enter in the A textfield, I want the focus to go to B, and so on.

Make the next textfield become the firstResponder. Anytime a textfield is firstResponder, the keyboard will appear.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.