Reputation: 2216
I have searched the forums regarding this and found no information on this error. I created a simple single view application in xcode and added code to create a test alert in viewDidLoad method.
- (void)viewDidLoad
{
[super viewDidLoad];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert Test"
message:@"Alert Test"
delegate:self
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
// Do any additional setup after loading the view, typically from a nib.
}
I have not added any other code. When I run this on my iphone 4 it runs without any problem. But when I click the home button of my iphone 4 with the alert displayed I get the mentioned error.
Device: iphone 4 OS: iOS 5.1.1
Please help. Thanks in advance
Upvotes: 0
Views: 248
Reputation: 8106
you should not display the alertView
in viewDidLoad, [UIAlertView show]
displays the alertView using animation. we should avoid animation performance when we are not in screen/view , display the alertView
in viewDidAppear
instead.
EDIT:
-(void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismiss) name:@"UIApplicationWillResignActiveNotification" object:nil];
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
alert = [[UIAlertView alloc]initWithTitle:@"test" message:@"test" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
//do not forget to add this in your header
-(void)dismiss{
[alert dismissWithClickedButtonIndex:-1 animated:NO];
}
Upvotes: 2