Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios5 从UIAlertView按钮调用方法_Ios5 - Fatal编程技术网

Ios5 从UIAlertView按钮调用方法

Ios5 从UIAlertView按钮调用方法,ios5,Ios5,我创建了一个警报视图,要求输入一些密码,但我想知道如何仅在单击“继续”按钮时调用一个方法 这是我的代码: -(IBAction)setUserAlert:(id)sender{ UIAlertView *setPassword = [[UIAlertView alloc] initWithTitle:@"Insert Password" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Conti

我创建了一个警报视图,要求输入一些密码,但我想知道如何仅在单击“继续”按钮时调用一个方法

这是我的代码:

-(IBAction)setUserAlert:(id)sender{

UIAlertView *setPassword = [[UIAlertView alloc] initWithTitle:@"Insert Password" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];

   //The password isn´t visible.
    setPassword.alertViewStyle = UIAlertViewStyleSecureTextInput;
   [setPassword show];

    // Call the method that i want to call only after you click "Continue".
    [self displayMessage:(UIButton *)sender];
        }
    }
//仅当长度>=6且密码匹配时才启用该按钮

-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView{
//Defining the password 
NSString *password = [[NSString alloc]initWithFormat:@"12345678"];
UITextField *setPassword = [alertView textFieldAtIndex:0];

  if ([setPassword.text length] >= 6 && [setPassword.text isEqualToString:password]){
    return YES;
  }
return NO;
}
//单击“继续”后,我要调用的操作

我想在这一个里面调用“displayMessage”,但我不知道怎么做,也不知道它是否正确

-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
 if (buttonIndex == 1){
    // call displayMessage,  sends and error.  
 }  
}

如果代理是self,则添加
alertView:clickedbuttonindex:
方法,并确定索引是否按了“Continue”。

您必须根据需要调用代理方法-(无效)alertView:(UIAlertView*)操作表单击按钮索引:(NSInteger)按钮索引表示您的应用程序将崩溃。然后在调试模式下运行你的应用程序,它就会知道你的应用程序是在委托方法中崩溃还是在显示消息方法中崩溃。我修复了它,忘记了“显示消息”方法,但这可能不是最好的方法。-(iAction)alertView:(UIAlertView*)操作表ClickedButtonIndex:(NSInteger)buttonIndex{//如果(buttonIndex==1){u user.text=[[NSString alloc]initWithFormat:@“Hola Mony”],用户单击了一个确定/取消按钮imageUser.hidden=YES;goodUser.hidden=NO;backgound.hidden=YES;yesButton.hidden=YES;noButton.hidden=YES;userLabel.hidden=YES;}
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
 if (buttonIndex == 1){
    // call displayMessage,  sends and error.  
 }  
}