我有点问题。我将uiAlertView子类化,并将其命名为uiDisclaimerAlertView。
到目前为止,子类工作得很好。但现在我想用这个类作为自己的代理。所以在我的子类中,我使用了:
self.delegate = self;
我这么做是因为我想把所有的都放在同一个类文件中。
现在我面临的问题是我的委托方法被调用,但是参数是
(null)
.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"Trying: %@", buttonIndex);
}
[super setDelegate: self];
#import "UIDisclaimerAlertView.h"
#import "PremierSoinsAppDelegate.h"
#import "BlocTexte.h"
@implementation UIDisclaimerAlertView
@synthesize dialogKey, plist, plistPath;
- (id)initWithKeyAndBlocTexteId:(NSString *)key BlocTexteId:(NSString *)blocTexteId
{
if (self = [super init])
{
// Fetching content
BlocTexte *blocTexte = [[BlocTexte alloc] init];
NSString *messageString = [[blocTexte getBlocTextes:blocTexteId] objectAtIndex:1];
// Setting superclass' properties
self.title = @"Disclaimer";
self.message = messageString;
[super setDelegate: self];
[self addButtonWithTitle: @"Ok"];
[self addButtonWithTitle: @"Toujours"];
// Setting plist key
self.dialogKey = key;
// Loading plist content
PremierSoinsAppDelegate *AppDelegate = (PremierSoinsAppDelegate *)[[UIApplication sharedApplication] delegate];
self.plistPath = [AppDelegate saveFilePath:@"disclaimers.plist"];
self.plist = [[NSMutableDictionary alloc] initWithContentsOfFile:self.plistPath];
[blocTexte release];
}
return self;
}
- (void)show {
[super show];
}
- (void)toujours
{
[self.plist setValue:@"1" forKey:self.dialogKey];
[self.plist writeToFile:self.plistPath atomically:YES];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"Trying: %@", buttonIndex);
}
@end