我正在尝试处理 UIAlertView 的解雇事件。但是 didDismissWithButtonIndex 永远不会被调用。下面是我在其中生成警报的单例类的代码。有人能发现我做错了什么吗?
MySingleton.h
@interface BMAppUser : NSObject <UIAlertViewDelegate> {
}
+ (id)sharedInstance;
MySingleton.m
+ (id) sharedInstance {
static BMAppUser *sharedInstance = nil;
@synchronized(self) {
if (sharedInstance==nil) {
sharedInstance = [[super allocWithZone:NULL] init];
}
}
return sharedInstance;
}
-(void)promptToSetLanguagePreferences {
// Create a new alert object and set initial values.
NSString *message = [NSString stringWithFormat:@"Please set your language preference settings. Click OK to go there now."];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Language Preferences Not Set"
message:message
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
// Display the alert to the user
[alert show];
}
-(void)alertView:(UIAlertView *)didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"THIS METHOD NEVER GETS CALLED!!!!!!!");
if(buttonIndex==0){
NSLog(@"userclickedCancel");
}
if(buttonIndex==1){
NSLog(@"userclickedOK");
}
}