嵌套的UIAlertView逻辑

时间:2013-03-13 13:16:09

标签: iphone ios objective-c uialertview nested

在我的应用程序中,我有按钮,允许用户购买当前项目。

我希望用户确认,他接受销售协议,然后他选择他的优惠付款方式。

我背后的逻辑是:

用户点击购买按钮后,弹出UIAlertView:

NSMutableString *msg = [[NSMutableString alloc] initWithFormat:@"By recognizing this agreement you agree, that in following 15 minutes you will pay for %@ which has price of %@, if you won't make the payment, your account may be blocked for this item.",mainTitle.text,buyoutPrice.text];
    UIAlertView *buyoutAlert = [[UIAlertView alloc] initWithTitle:@"Buyout" message:msg
                                                       delegate:self cancelButtonTitle:@"I don't agree" otherButtonTitles:@"I agree",nil];
    buyoutAlert.tag = 1;
    [buyoutAlert show];

在我的 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
我正在检查他是否接受......

        - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(alertView.tag == 1)
        {
            if(buttonIndex == 1)
            {
                UIAlertView *typeBuyout = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Anonymous payment", nil)
                                                       message:NSLocalizedString(@"Do you wish to make payment as anon?", nil)
                                                      delegate:nil
                                             cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
                                             otherButtonTitles:@"Anon buyout",@"Regular buyout",nil];
                typeBuyout.tag = 2;

                [typeBuyout show];

            }
        }


if(alertView.tag == 2)
{

        if(buttonIndex == 1)
        {
            //anon
            NSLog(@"anon");
        }else if(buttonIndex == 2)
        {
            //normal 
            NSLog(@"Normal");
        }
    }

我的问题是,在提交用户第二个警报(typeBuyout)之后,在用户做出选择之后,clickedButtonAtIndex不会触发。

我试图在viewDidLoad和clickedButtonAtIndex中定义我的typeBuyout警报只是[typebuyout show];但结果相同。

2 个答案:

答案 0 :(得分:3)

在第二个警告中,你没有给代表自己,你是没有。看看

答案 1 :(得分:2)

为第二个alertview设置委托以调用clickedButtonAtIndex方法

if(buttonIndex == 1)
 {
            UIAlertView *typeBuyout = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Anonymous payment", nil)
                                                   message:NSLocalizedString(@"Do you wish to make payment as anon?", nil)
                                                  delegate:self
                                         cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
                                         otherButtonTitles:@"Anon buyout",@"Regular buyout",nil];
            typeBuyout.tag = 2;

            [typeBuyout show];

        }