以下是该方案。
我在Controller的viewDidLoad中创建了一个UIAlertView,其中显示了Alert。
loginAlert = [[UIAlertView alloc] initWithTitle:@"Check"
message:@"Ok"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
我将其称为[提示显示]并显示。
当用户按下Ok时,它会转到textEndEditing委托方法,如果输入了nil / worng值,我再次调用[alert show]。
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if ([textField.text length] > 0)
{
}
else
{
NSLog(@"Checking");
[loginAlert show];
}
}
但它没有再显示出来。请告诉我该怎么办?
答案 0 :(得分:3)
而不是delegate:nil
,请delegate:self
loginAlert = [[UIAlertView alloc] initWithTitle:@"Check"
message:@"Ok"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
答案 1 :(得分:1)
首先将您的提醒视图委托更改为自己。
loginAlert = [[UIAlertView alloc] initWithTitle:@"Check"
message:@"Ok"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
[loginAlert show];
然后在警报视图中委托方法检查文本的长度,如果为空,则再次显示警报。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
if ([[loginAlert textFieldAtIndex:0].text length] > 0)
{
}
else
{
NSLog(@"Checking");
[loginAlert show];
}
}
}
答案 2 :(得分:0)
试试这个:
loginAlert = [[UIAlertView alloc] initWithTitle:@"Check"
message:@"Ok"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
[yourTextField resignFirstResponder];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField==yourTextField) {
if ([yourTextField.text isEqualToString:@""] || yourTextField.text == nil) {
[yourAlert show];
}
}
}
另请参阅此问题:
答案 3 :(得分:0)
设置委托self
而不是nil
并实施我的代码。
loginAlert = [[UIAlertView alloc] initWithTitle:@"Check"
message:@"Ok"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
[self.view endEditing:YES];
}
}
答案 4 :(得分:0)
如何简化......?
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if ([textField.text length] > 0)
{
}
else
{
NSLog(@"Checking");
loginAlert = [[UIAlertView alloc] initWithTitle:@"Check"
message:@"Ok"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
[loginAlert show];
}
}
答案 5 :(得分:0)
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
// Your code write in this method and show your alert
}
else
{
[loginalert show];
}
}
我希望这段代码对你有用。