0
votes

I created many buttons before, but for some reason I'm having trouble creating a simple button.

In my viewDidLoad method I created a very basic button:

_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_button.frame = CGRectMake(0, 0, 100, 25);
[_button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_button];

- (void)buttonClicked:(id)sender
{
    NSLog(@"%@", sender);
    NSLog(@"Download issue");
}

But for some reason when I click on it I'm just getting an error

* -[DownloadButtonViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x6ac2af0

I have no idea what's going wrong as the code is exactly the same as every button I created before ... (probably just having a bad day ...)

2
Are you using ARC ? If not, your button should be retained. - Julien
But it's not the button that is deallocated, but the view controller itself! Don't you read that error message? - user529758

2 Answers

10
votes

Your view controller itself is being deallocated. Maybe you're using ARC and you don't have a strong reference to your view controller, so it's deallocated immediately after creation.

0
votes

I have just Copy pasted your code and it's working fine here,it might be possible you are realeasing it some where by mistake because that object is Autoreleased it self and H2CO3 as said is also true.