无法设置 UIAlertview 事件? [英] Can't set UIAlertview events?

查看:23
本文介绍了无法设置 UIAlertview 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法为 alertview 设置操作事件.在这里,当我单击 alertview 按钮时,无法对其进行操作.我的代码有什么问题.

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.

这是我的代码:

-(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.

推荐答案

消息被发送到您指定为 nil 的委托.将委托设置为 self,它会起作用.

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];

这篇关于无法设置 UIAlertview 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆