Можно ли показать предупреждение в методе alertview `clickedButtonAtIndex` - PullRequest
0 голосов
/ 18 августа 2011

В методе делегата UIalerview Я пытаюсь показать еще одно предупреждение после завершения процесса нажатия кнопки индекса. Возможно ли это сделать? Также я хочу вызвать метод по нажатию кнопки оповещения. Как я могу это сделать?

Я пытаюсь таким образом. Это правильно?

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    if(buttonIndex == 1)
    {
        inappPurchaseViewController  = [[InAppPurchaseViewController alloc] init];
        [inappPurchaseViewController Upgrade:nil];
        [inappPurchaseViewController release];

        UIAlertView *purchasedone = [[UIAlertView alloc] initWithTitle:@"Enable Ads" message:@"You can Enable Ads from Settings Option" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [purchasedone show];
        [purchasedone release];
    }  
}

Ответы [ 3 ]

2 голосов
/ 18 августа 2011

Вы хотите использовать теги для вашего UIAlertViews

Назначение тегов

UIAlertView *firstAlert = [[UIAlertView alloc] initWithTitle:@"Do something first" message:@"This is the first UIAlertView" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[firstAlert setTag: 0];
[firstAlert show];
[firstAlert release];

Обработка этих тегов

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    switch (alertView.tag)
    {
        case 0: /* firstAlert */
        {
            if(buttonIndex == 1)
            {
                inappPurchaseViewController  = [[InAppPurchaseViewController alloc] init];
                [inappPurchaseViewController Upgrade:nil];
                [inappPurchaseViewController release];

                UIAlertView *purchaseDone = [[UIAlertView alloc] initWithTitle:@"Enable Ads" message:@"You can Enable Ads from Settings Option" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [purchaseDone setTag: 1];
                [purchaseDone show];
                [purchaseDone release];
            } 
        }
            break;
        case 1: /* purchaseDone */
        {
            /*  purchaseDone uialertview was triggered, handle it here.   */
        }
            break;
    }
}
0 голосов
/ 18 августа 2011

поместите следующую строку поверх вашего файла .m

`#define PREVIOUS_ALERT 101`
`#define NEW_ALERT 102`

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //you need to make a condition here for checking the alert else it will go into infinite loom of showing alert after alert
    //you can do it by setting tag to alert something like this
    if(alertView.tag == PREVIOUS_ALERT) //sot the previous alert tag to this where you created it
    {
        if(buttonIndex == 1)
        {

            inappPurchaseViewController  = [[InAppPurchaseViewController alloc] init];
            [inappPurchaseViewController Upgrade:nil];
            [inappPurchaseViewController release];


            UIAlertView *purchasedone = [[UIAlertView alloc] initWithTitle:@"Enable Ads" message:@"You can Enable Ads from Settings Option" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            purchasedone.tag = NEW_ALERT;
            [purchasedone show];
            [purchasedone release];
        }  
    }
    else
    {
        //code for your second alert
    }
}
0 голосов
/ 18 августа 2011
 UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"a" message:@"b" delegate:self        cancelButtonTitle:@"OK" otherButtonTitles:@"ca",nil];
[a show];
[a release];


 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if(buttonIndex == 1)
{
    UIAlertView *purchasedone = [[UIAlertView alloc] initWithTitle:@"Enable Ads" message:@"You can Enable Ads from Settings Option" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    purchasedone.tag = 55;
    [purchasedone show];
    [purchasedone release];

}  

if([alertView tag] == 55 && buttonIndex == 0)
{
    UIAlertView *purchasedone = [[UIAlertView alloc] initWithTitle:@"New Alert" message:@"New Alert Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [purchasedone show];
    [purchasedone release];
}

}

записать UIAlertViewDelegate в файл .h.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...