//.h 文件 #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITextFieldDelegate> // type 选择outlet 然后在后面加上。<UITextFieldDelegate> @property (retain, nonatomic) IBOutlet UITextField *TXF; //.c文件 中。 #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize TXF; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [TXF setDelegate:self]; //不要忘了这。 } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } //可用于在TXT输入时的判断。在输入之前先判断。把回BOOL型 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { NSLog(@"first...\n"); return YES; } @end