开发者

IPhone app xcode, trying to hide text input by clicking on the background?

I'm following an example in Beginning Iphone Development 4 for basic user interaction.

I'm using xcode 4.02 with sdk 4.3

I have a basic viewcontroller.xib with two textbox's, one for numeric values and another for text. Once I'm finished editing either of the text fields I wish to tap开发者_JS百科 the background and have the keypad disappear.

The books says to change the container UIView object to a UIControl and then add an action onto the UIControl event Touch Down. Then create a method to resign the first responder of each of the textbox's and link this to the touch down event. I've done this. Here is my code, is there anything I've missed? At the moment nothing happens.

IPhone app xcode, trying to hide text input by clicking on the background?

Thanks

@interface ControlFunViewController : UIViewController {
    UITextField *nameField;
    UITextField *numberField;
}

@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *numberField;

- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;

Implementation:

#import "ControlFunViewController.h"

@implementation ControlFunViewController

@synthesize nameField;
@synthesize numberField;

- (void)dealloc
{
    [nameField release];
    [numberField release];
    [super dealloc];
}

- (IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender {
    [nameField resignFirstResponder];
    [numberField resignFirstResponder];
}


This link will help you. It addresses hiding the keyboard in several different ways. http://www.mobisoftinfotech.com/blog/iphone/iphone-uitextfield-tutorial-handling-keyboard-interactions/

I actually had the same exact problem in the same book earlier this year. I realized that I wasn't reading carefully and missed just one small instruction so I re-read it carefully and it worked.


Change the UIView to UIControl from the identify tab of inspector ->class identity section. add this

-(IBACTION)tabBackground: (id) sender; 

to your .h file

add this to your .m file

-(IBACTION) tabBackgroup: (id)sender {
[nameField resignFirstRespnder];
[numberField resignFirstResponder];
}

connect your tabBackgroupnd from the inspector, action receive section to the UIVIEW (which is an UIControl now) and your good to go. let me know if you have anyproblem


Found the answer, I didn't link up the outlets for the text boxes so the controller didn't no they existed. School boy error.

http://www.iphonedevbook.com/forum/chapter-4-more-user-interface-fun/4145-backgroundtap.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜