开发者

clickedButtonAtIndex in appdelegate is not called

I am calling UIAlert with 2 buttons "Cancel" and "OK" in MyapplicationAppDelegate.m file , the alert is called but on tap of "Cancel" or "OK" button

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

meth开发者_运维技巧od is not called.

I have added UIAlertViewDelegate in the MyapplicationAppDelegate.h file as below

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

I want to know what else is required.


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> { .. }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜