无法设置 UIAlertview 事件?

发布于 2024-12-11 10:01:57 字数 1767 浏览 0 评论 0原文

我无法为警报视图设置操作事件。在这里,当我单击警报视图按钮时,它无法执行操作。我的代码有什么问题。

这是我的代码:

-(IBAction)savebuttons
{
if([username.text isEqualToString:@""] && [password.text isEqualToString:@""] && [emailid.text isEqualToString:@""] && [phonenum.text isEqualToString:@""] && [address.text isEqualToString:@""] && [city.text isEqualToString:@""] && [state.text isEqualToString:@""] && [country.text isEqualToString:@""] && [zipcode.text isEqualToString:@""]) {
    UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Please enter all the details" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [view show];
    [view release];
}   
else if([username.text isEqualToString:@""])
{
    views = [[UIAlertView alloc] initWithTitle:@"Email ID" message:@"Email ID cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    views.tag=1;
    [views show];
    [views release];

}
else if([password.text isEqualToString:@""]){
    UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Password" message:@"Password cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    view.tag=2;
    [view show];
    [view release];
}
   else
   {

    .....
     ......
}

- (void)alertView:(UIAlertView *)alertViews clickedButtonAtIndex:(NSInteger)buttonIndex
{
      if(alertViews.tag == 1)
      {
          if(buttonIndex == 0)
          {
    [username becomeFirstResponder];
    NSLog(@"Username");
         }
     }
     if(alertViews.tag == 2)
      {
          if(buttonIndex == 0)
          {
    [password becomeFirstResponder];
    NSLog(@"Password");
         }
}

我只有一个警报视图按钮,例如“确定”。但它没有回应。

I can't set action event for alertview. Here when I click the alertview button it can't be actioned. What's the problem in my code.

Here is my code :

-(IBAction)savebuttons
{
if([username.text isEqualToString:@""] && [password.text isEqualToString:@""] && [emailid.text isEqualToString:@""] && [phonenum.text isEqualToString:@""] && [address.text isEqualToString:@""] && [city.text isEqualToString:@""] && [state.text isEqualToString:@""] && [country.text isEqualToString:@""] && [zipcode.text isEqualToString:@""]) {
    UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Please enter all the details" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [view show];
    [view release];
}   
else if([username.text isEqualToString:@""])
{
    views = [[UIAlertView alloc] initWithTitle:@"Email ID" message:@"Email ID cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    views.tag=1;
    [views show];
    [views release];

}
else if([password.text isEqualToString:@""]){
    UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Password" message:@"Password cannot be blank" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    view.tag=2;
    [view show];
    [view release];
}
   else
   {

    .....
     ......
}

- (void)alertView:(UIAlertView *)alertViews clickedButtonAtIndex:(NSInteger)buttonIndex
{
      if(alertViews.tag == 1)
      {
          if(buttonIndex == 0)
          {
    [username becomeFirstResponder];
    NSLog(@"Username");
         }
     }
     if(alertViews.tag == 2)
      {
          if(buttonIndex == 0)
          {
    [password becomeFirstResponder];
    NSLog(@"Password");
         }
}

I have only one button for alertview like "OK". But it's not responding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惜醉颜 2024-12-18 10:01:57

您已将警报视图的委托设置为nil,将其设置为self,如果您没有设置委托,则不会调用委托方法

you have set delegate of alert views to nil, set it to self, if you did not set delegate , delegate methods are not called

握住我的手 2024-12-18 10:01:57

消息被发送到委托,您将其指定为 nil。将 delegate 设置为 self,就可以了。

UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Warning" 
    message:@"Please enter all the details" 
    delegate:self 
    cancelButtonTitle:@"Dismiss" 
    otherButtonTitles:nil];

The message gets sent to the delegate, which you specified as nil. Set the delegate to self, and it would work.

UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Warning" 
    message:@"Please enter all the details" 
    delegate:self 
    cancelButtonTitle:@"Dismiss" 
    otherButtonTitles:nil];
纵情客 2024-12-18 10:01:57
UIAlertView *myAlert = [[UIAlertView alloc]
               initWithTitle:@"Alert !!" message:@"This is my Alert" 
               delegate:self cancelButtonTitle:@"Cancel"                     
               otherButtonTitles:@"OK",nil];
   [myAlert show];
   myAlert.tag = 1;
   [myAlert release];


   // Delegate Method of UIAlert :
  - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  {
      if (buttonIndex==1 && myAlert.tag == 1) 
       {
            // Action to be done/ called on button index 1 (OK button) of myAlert
       }
      else if (buttonIndex==0 && myAlert.tag == 1)
       {
            // Action to be done/ called on button index 0 (Cancel button) of myAlert
       }
  }
UIAlertView *myAlert = [[UIAlertView alloc]
               initWithTitle:@"Alert !!" message:@"This is my Alert" 
               delegate:self cancelButtonTitle:@"Cancel"                     
               otherButtonTitles:@"OK",nil];
   [myAlert show];
   myAlert.tag = 1;
   [myAlert release];


   // Delegate Method of UIAlert :
  - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  {
      if (buttonIndex==1 && myAlert.tag == 1) 
       {
            // Action to be done/ called on button index 1 (OK button) of myAlert
       }
      else if (buttonIndex==0 && myAlert.tag == 1)
       {
            // Action to be done/ called on button index 0 (Cancel button) of myAlert
       }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文