views:

39

answers:

1

The problem is after i press 2 buttons the App crashes and I can't figure out why

Button1 is wired to button1 Button2 is wired to button2 ... Button5 is wired to button5

What am I doing wrong?

Basically I want to check if the sequence of #'s is punched in correctly (55235)

In my AppDelegate.H file, I've defined a variable called

NSString* myEasterEgg;

In AppDelegate.M, I have 5 buttons that are correctly wired and each button has it's own method

-(IBAction)button1:(id)sender
{
if(CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0)
{
myEasterEgg = @"";
} else {
myEasterEgg = [myEasterEgg stringByAppendingString:@"1"];
}
}

-(IBAction)button2:(id)sender
{
if(CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0)
{
myEasterEgg = @"";
} else {
myEasterEgg = [myEasterEgg stringByAppendingString:@"2"];
}
}

-(IBAction)button3:(id)sender
{
if(CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0)
{
myEasterEgg = @"";
} else {
myEasterEgg = [myEasterEgg stringByAppendingString:@"3"];
}
}

-(IBAction)button4:(id)sender
{
if(CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0)
{
myEasterEgg = @"";
} else {
myEasterEgg = [myEasterEgg stringByAppendingString:@"4"];
}
}

-(IBAction)button5:(id)sender
{
if(CFStringCompare((CFStringRef)myEasterEgg, (CFStringRef)@"52235", 1) == 0)
{
myEasterEgg = @"";
} else {
myEasterEgg = [myEasterEgg stringByAppendingString:@"5"];
}
}

-(void)viewDidLoad
{
myEasterEgg = [[NSString alloc] initWithString:@""];
}
+1  A: 

You are leaking your original string, and replacing it with new values without retaining them. The crash happens because you’re calling [myEasterEgg stringByAppendingString:…] on a dangling pointer, that is, a variable which no longer refers to any object. See the Memory Management Programming Guide for more information.

Ahruman
I'm at work and when I click that link causes HTML rendering issues. Could you please tell me how I can fix it?
software is fun
Get a new browser?
kperryua
I'm using IE6 because we're not allowed to install a real browser.
software is fun