I create a button at runtime. The button appears but crashes the app with an NSException error when I click on it. I don't see what the issue is. I need a pair of new eyes. Thanks.
Code:
-(void)setupInterface {
//button
CGRect frame = CGRectMake(100.0, 100.0, 70.0, 20.0);
UIButton *btn = [[UIButton alloc] initWithFrame:frame];
[btn setTitle:@"Button" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown];
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[btn addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:btn];
[btn autorelease];
}
Code:
- (void)doneButton:(id)sender {
//problem here*
//[self removeFromSuperview];
NSLog(@"press");
}