Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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
Ios 将buttonIndex与多个警报视图一起使用_Ios_Uialertview - Fatal编程技术网

Ios 将buttonIndex与多个警报视图一起使用

Ios 将buttonIndex与多个警报视图一起使用,ios,uialertview,Ios,Uialertview,我有大约4个警报视图,它们出现时具有不同的条件。在所有4个视图中,右按钮应始终执行相同的操作 我使用下面的代码尝试说,如果buttonIndex==1,请执行一些操作 目前,它只在我的一个警报视图中工作。其他人只是关闭了警报视图,并且从不运行IF buttonIndex==1的代码 任何想法都将不胜感激 if (a==1) { NSString *message = [[NSString alloc] initWithFormat:

我有大约4个警报视图,它们出现时具有不同的条件。在所有4个视图中,右按钮应始终执行相同的操作

我使用下面的代码尝试说,如果buttonIndex==1,请执行一些操作

目前,它只在我的一个警报视图中工作。其他人只是关闭了警报视图,并且从不运行IF buttonIndex==1的代码

任何想法都将不胜感激

if (a==1) {
            NSString *message = [[NSString alloc] initWithFormat:
                             @"Only $%@!",dollas.text];

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
                              @"Really?!"

                                                        message:message
                                                       delegate:self
                                              cancelButtonTitle:@"Close"
                                              otherButtonTitles:@"Facebook",nil];
        [alert show];
        [alert release];
        [message release];

        }

else if (a==2) {
            NSString *message = [[NSString alloc] initWithFormat:
                                 @"Somone just paid you $%@", dollas.text];

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
                                  @"Swish!"

                                                            message:message
                                                           delegate:nil
                                                  cancelButtonTitle:@"Close"
                                                  otherButtonTitles:@"Facebook",nil];
            [alert show];
            [alert release];
            [message release];

        }
代表:

- (void)alertView:(UIAlertView *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1)
    {
       do.stuff;
    }

在每个alertview和inside-didDismissWithButtonIndex上设置标记,首先检查alerts标记

例如:

然后使用ButtonIndex进行in-DidDismiss

- (void)alertView:(UIAlertView *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1 && actionSheet.tag == 1)
    {
       do.stuff;
    }
    else if (buttonIndex == 1 && actionSheet.tag == 2)
    {
       do.otherStuff;
    }

在每个alertview和inside-didDismissWithButtonIndex上设置标记,首先检查alerts标记

例如:

然后使用ButtonIndex进行in-DidDismiss

- (void)alertView:(UIAlertView *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1 && actionSheet.tag == 1)
    {
       do.stuff;
    }
    else if (buttonIndex == 1 && actionSheet.tag == 2)
    {
       do.otherStuff;
    }

对于案例(a==2),您将
UIAlertView
委托设置为nil,因此
-(void)alertView:(UIAlertView*)操作表didDismissWithButtonIndex:(NSInteger)buttonIndex
在这种情况下甚至不应该被调用。将其更改为将委托设置为self。

对于案例(a==2),您将
UIAlertView
委托设置为nil,因此
-(void)alertView:(UIAlertView*)操作表didDismissWithButtonIndex:(NSInteger)buttonIndex
甚至不应该被调用。将其更改为将委托设置为self。

您应该将委托设置为
self
,以便调用该方法


您应该将委托设置为
self
,以便调用该方法


非常感谢。这正是我需要的。谢谢!这正是我需要的。谢谢你的回答。实际上,我需要在UIAlertViews中将delegate:nil改为delegate:self,感谢您的回答。实际上,我需要在UIAlertViews中将delegate:nil更改为delegate:self,而不使用
按钮index==1
。相反,使用
buttonIndex==alertView.firstOtherButtonIndex
buttonIndex==alertView.cancelButtonIndex
。哦,太好了。我不知道我能做到。谢谢如果每个警报之间的唯一区别是标题和消息,那么就使用变量,然后使用一组代码创建和显示警报视图。重复同一代码毫无意义。不要使用
按钮索引==1
。相反,使用
buttonIndex==alertView.firstOtherButtonIndex
buttonIndex==alertView.cancelButtonIndex
。哦,太好了。我不知道我能做到。谢谢如果每个警报之间的唯一区别是标题和消息,那么就使用变量,然后使用一组代码创建和显示警报视图。一遍又一遍地重复相同的代码是没有意义的。
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
                      @"Really?!"

                                                message:message
                                               delegate:self //SELF
                                      cancelButtonTitle:@"Close"
                                      otherButtonTitles:@"Facebook",nil];