我有四个UITextFields,我想在UIAlertView中使用步骤,目前这是它看起来像如何通过多个UITextFields
我想做什么就能做的是一旦达到4个字符的限制,每个字段限制每个字段为4个字符,然后我希望下一个UITextField成为第一个响应者。
我也想能够做到这一点反向,所以如果字符被删除,一旦没有在第二场可用字符到第一,并开始删除等
目前我的代码是非常马虎,因为我只是想得到像这样的工作..所以这是它看起来像迄今为止。
//提示用户输入注册在这里 UIAlertView中*警报= [[UIAlertView中页头] initWithTitle:@ “请注册设备” 消息:@ “ ”代表:无cancelButtonTitle:@“ OK” otherButtonTitles:无]。
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 53, 30)];
UITextField *myTextField1 = [[UITextField alloc] initWithFrame:CGRectMake(77, 45, 53, 30)];
UITextField *myTextField2 = [[UITextField alloc] initWithFrame:CGRectMake(142, 45, 53, 30)];
UITextField *myTextField3 = [[UITextField alloc] initWithFrame:CGRectMake(207, 45, 53, 30)];
// need to do something with first reasponder once 4 digits has been entered per box etc.
[myTextField becomeFirstResponder];
myTextField.placeholder [email protected]"AAAA";
myTextField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField.textAlignment = NSTextAlignmentCenter;
myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField1.placeholder [email protected]"AAAA";
myTextField1.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField1.textAlignment = NSTextAlignmentCenter;
myTextField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField2.placeholder [email protected]"AAAA";
myTextField2.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField2.textAlignment = NSTextAlignmentCenter;
myTextField2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField3.placeholder [email protected]"AAAA";
myTextField3.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
myTextField3.textAlignment = NSTextAlignmentCenter;
myTextField3.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myTextField1 setBackgroundColor:[UIColor whiteColor]];
[myTextField2 setBackgroundColor:[UIColor whiteColor]];
[myTextField3 setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert addSubview:myTextField1];
[alert addSubview:myTextField2];
[alert addSubview:myTextField3];
[alert show];
任何帮助将不胜感激。
// UPDATE: 这是我想使用的委托方法
//.h
<UITextFieldDelegate>
//.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//..
[self.myTextField setDelegate:self];
[self.myTextField1 setDelegate:self];
[self.myTextField2 setDelegate:self];
[self.myTextField3 setDelegate:self];
//..
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSLog(@"yay");
return NO;
}
好吧我会尽力处理这个..只是有一个问题与我的shouldChangeCharactersInRange委托方法不被调用,即使我已经将UITextFieldDelegate添加到标题中,并在viewDidLoad方法中设置委托.. – HurkNburkS
这很奇怪,可以你也分享那个代码? – Raspu
我用示例代码更新了我的问题,底部显示了我如何使用文本字段委托。 – HurkNburkS