【发布时间】:2014-05-31 14:07:24
【问题描述】:
当按下返回键或返回键时,我希望 firstResponder 转到前一个 TextField。但是 textFieldShouldReturn 没有启动。非常感谢你们!
试过this,但似乎不起作用。
MyViewController.h
@interface MyViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *firstCodeField;
MyViewController.m
@synthesize firstCodeField;
- (void)viewDidLoad
{
[super viewDidLoad];
firstCodeField.delegate = self;
secondCodeField.delegate = self;
thirdCodeField.delegate = self;
fourthCodeField.delegate = self;
fifthCodeField.delegate = self;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSUInteger newLength = [textField.text length] + [string length] - range.length;
if (string.length == 0 && textField.text.length)
{
if(textField==fifthCodeField) {
NSLog(@"It goes to fourth textfield but doesn't clear the number in the cell.");
[textField resignFirstResponder];
[fourthCodeField becomeFirstResponder];
return NO;
}
}
return (newLength > 1) ? NO : YES;
}
【问题讨论】:
-
检查文本字段的代表
标签: ios objective-c uitextfield uitextfielddelegate