代码之家  ›  专栏  ›  技术社区  ›  Tommy B.

对uialertview进行子类化并将子类用作委托时出现问题

  •  0
  • Tommy B.  · 技术社区  · 15 年前

    我有点问题。我将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
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   Noah Witherspoon    15 年前

    %@ 格式化程序的功能不适合使用:您正在寻找 %d %i . 你可能很困惑 NSInteger _ int 在32位的系统上,比如iPhone_ NSNumber ,用作通用数字保持器的对象类型。

    推荐文章