views:

17

answers:

1

Hi

I'm having a little problem. I subclass'd UIAlertView and I named it UIDisclaimerAlertView.

So far so good, the subclass is working fine. But now I wanted to use this very class as its own delegate. So in my subclass I used : self.delegate = self; I did this because I wanted it all in the same class file.

Now the problem I'm facing is that my delegates' methods get called, but the parameters are (null).

For example:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"Trying: %@", buttonIndex);
}

Returns (null) everytimes. Any ideas why? I also tried [super setDelegate: self]; (to tell directly the superclass (UIAlertView)) and it does the same thing.

Here's the complete implementation file:

#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
+1  A: 

buttonIndex isn't a pointer, so the %@ formatter thing isn't the right one to use: you're looking for %d or %i. You may be confusing NSInteger—a primitive type, which is typedef'd as int on 32-bit systems like the iPhone—with NSNumber, an object type that acts as a generic number-holder.

Noah Witherspoon
Oh crap, I'm so dumb. I always do the same error! Thanks for this, it now works...
Tom