clickedButtonAtIndex в appdelegate не вызывается - PullRequest
4 голосов
/ 11 августа 2011

Я вызываю UIAlert с двумя кнопками «Отмена» и «ОК» в файле MyapplicationAppDelegate.m, предупреждение вызывается, но при нажатии кнопки «Отмена» или «ОК»не называется.

Я добавил UIAlertViewDelegate в файл MyapplicationAppDelegate.h, как показано ниже

#import UIKit/UIKit.h
@interface MyapplicationAppDelegate: NSObject UIApplicationDelegate,UIAlertViewDelegate
{
..
}

Я хочу знать, что еще требуется.

Ответы [ 2 ]

5 голосов
/ 11 августа 2011

Я не уверен, является ли это вашей опечаткой во время публикации вопроса, но вы должны вызвать делегата в <.., ..>

@interface MyapplicationAppDelegate: NSObject <UIApplicationDelegate,UIAlertViewDelegate> { .. }

Вот пример кода для UIAlertView

UIAlertView *myAlertView = [[UIAlertView alloc]initWithTitle:@""message:@"Your message goes here" delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil];
    [myAlertView show];
    [myAlertView release];

Я не уверен, что myAlertView.delgate = self - правильный метод, но я устанавливаю делегата с помощью initWithTitle

2 голосов
/ 09 мая 2013

Для меня

#define appDelegate ((AppDelegate*)[UIApplication sharedApplication].delegate)

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil 
                             message:@"Say Yes or NO?" delegate:appDelegate 
                             cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    alertView.tag = 1;
    [alertView show];
    [alertView release];

сделать трюк!

Теперь оно входит, -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; в файле AppDelegate без добавления,

@interface MyapplicationAppDelegate: NSObject <UIApplicationDelegate,UIAlertViewDelegate> { .. }
...