tags:

views:

34

answers:

0

I have a class file which is subclass of UIAlertView and adding image in alertView.But the problem is that when i call it the application crash.Here is my class

CustomAlert.h

#import <UIKit/UIKit.h>


@interface CustomAlert : UIAlertView {
    UILabel *alertTextLabel;
    UIImage *backgroundImage;
    //UITextField *nameTextField;
}

@property(readwrite, retain) UIImage *backgroundImage;
@property(readwrite, retain) NSString *alertText;
//@property(readwrite, retain)  UITextField *nameTextField;

- (id) initWithImage:(UIImage *)backgroundImage text:(NSString *)text;


@end

customAlert.m

#import "CustomAlert.h" 
@implementation CustomAlert

@synthesize backgroundImage, alertText;

- (id)initWithImage:(UIImage *)image text:(NSString *)text {
    if ((self = [super init])) 
    { 
        self.backgroundImage = image;
        //self.alertText = text;

        int gamescore=0;

        NSLog(@"game score in alert =%i",gamescore);
        NSString *str=[[NSString alloc] initWithFormat:@"Your Total Score : %i\n\n\n\n",gamescore];

        [self initWithTitle:@"Score Submission" message:str delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];       


    }
    return self;
}

- (void) setAlertText:(NSString *)text {
    alertTextLabel.text = text;
}

- (NSString *) alertText {
    return alertTextLabel.text;
}


- (void)drawRect:(CGRect)rect {
    //CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGSize imageSize = self.backgroundImage.size;
    //CGContextDrawImage(ctx, CGRectMake(0, 0, imageSize.width, imageSize.height), self.backgroundImage.CGImage);
    [self.backgroundImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
}

- (void) layoutSubviews {

}

- (void) show {
    [super show];

    CGSize imageSize = self.backgroundImage.size;
    self.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
}


- (void)dealloc {
    [super dealloc];
}

when I call this method the app crashes.My question is how to call this custom alert.