clickedButtonAtIndex in appdelegate is not called

让人想犯罪 __ 提交于 2019-12-05 16:58:12

I am not sure whether its your typo while posting the question but you should call the delegate within <.. , .. >

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

Here is sample code for UIAlertView

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

I am not sure myAlertView.delgate = self is the right method but i do set delegate with initWithTitle

For me,

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

do the trick!

Now its going into, -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; in AppDelegate file without adding,

@interface MyapplicationAppDelegate: NSObject <UIApplicationDelegate,UIAlertViewDelegate> { .. }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!