Reputation: 5971
I have an error alert view that crash when I click "OK"
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"OK" forState:UIControlStateNormal];
[button setFrame:CGRectMake(10, 80, 266, 43)];
[button addTarget:self action:@selector(dismissError:) forControlEvents:UIControlEventTouchUpInside];
[alertView addSubview:button]; //This is a subview of
//...other stylings for the custom error alert view
errorWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
errorWindow.windowLevel = UIWindowLevelStatusBar;
errorWindow.hidden = NO;
[errorWindow addSubview:alertView];
[errorWindow makeKeyAndVisible];
}
This alertView is inside the custom ErrorAlert:UIView.
This alert shows up fine.
However, when click on "OK" button, app crashes, it never reached - (void)dismissError:(id)sender;
Am I adding the button at the wrong place? (It gives the generic int retVal=......EXC_BAD_ACCESS)
Upvotes: 0
Views: 398
Reputation: 15213
You should not create a new UIWindow unless you're showing something on an external display.
In iOS, windows do not have title bars, close boxes, or any other visual adornments. A window is always just a blank container for one or more views. Also, applications do not change their content by showing new windows. When you want to change the displayed content, you change the frontmost views of your window instead.
Take a look at View Programming Guide for iOS
Upvotes: 4