我正在尝试修复iOS 7+警报,允许我输入4位数代码,此时出现提示,但输入字段为空白且不允许我输入任何内容。
以下方法用于调用引脚代码选项,从segmentedAction
开始,如下所示;
-(void)segmentedAction:(id)sender{
UISegmentedControl *control = (UISegmentedControl *)sender;
NSString *pincode = [self.objSettingAdapter getPinCode];
NSString *patternCode = [self.objSettingAdapter getPatternCode];
NSInteger pincodetype = control.selectedSegmentIndex;
if ((![pincode length]>0) && pincodetype==0) {
[self takePinInputFromUser:@"Choose Your PIN Code"];
}else if((![patternCode length]>0) && pincodetype==1) {
[self takePatterInputFromUser:@"Draw Pattern"];
}else {
[self.objSettingAdapter setPinCodeType:control.selectedSegmentIndex];
}
}
-(void)buttonAction:(id)sender{
UIButton *btn = (UIButton *)sender;
NSString *pincode = [self.objSettingAdapter getPinCode];
NSString *patternCode = [self.objSettingAdapter getPatternCode];
if ([btn.titleLabel.text isEqualToString:@"Reset PIN"] && (![pincode length]>0)) {
[self takePinInputFromUser:@"Choose Your PIN Code"];
}else if ([btn.titleLabel.text isEqualToString:@"Reset Pattern"] && (![patternCode length]>0)) {
[self takePatterInputFromUser:@"Draw Pattern"];
}else {
[self.objSettingAdapter setPinCodeType:([btn.titleLabel.text isEqualToString:@"Reset PIN"] ? 0 : 1)];
}
}
-(void)takePinInputFromUser:(NSString *)title{
AlertPinCode *prompt = [AlertPinCode alloc];
prompt = [prompt initWithTitle:title message:@"\n\n" delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Done"];
[prompt show];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
AlertPinCode *alertPin = (AlertPinCode *) alertView;
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *userPin = [alertPin enteredText];
if ([userPin length]<4) {
[alertPin dismissWithClickedButtonIndex:0 animated:YES];
[self takePinInputFromUser:@"Chose 4 Digit PIN Code"];
}else {
[self.objSettingAdapter setPinCodeType:0];
[self.objSettingAdapter setPinCode:userPin];
}
}
}
答案 0 :(得分:0)
请尝试以下操作。
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
__weak typeof(UIAlertController) *weakAlertController = alertController;
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
__strong typeof(UIAlertController) *strongAlertController = weakAlertController;
UITextField *digitTextField = [strongAlertController.textFields firstObject];
NSString *pinCode = digitTextField.text;
NSLog(@"pin code: %@", pinCode);
// Do something with the PIN code
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"Input 4 Digit PIN Code";
}];
[self presentViewController:alertController animated:YES completion:nil];
答案 1 :(得分:-1)
您可以使用 UIAlertViewController