I am using a UIAlertview
and inside that one activity indicator in viewdidload()
.But i tried to remove its from superview after a delay but after removing UIAlertview
using following code i am not able to do anything in app.Is like a new transparent layer is still running above my view.
CODE
-(void)startAlertActivity
{
_alertView = [[UIAlertView alloc] initWithTitle:@"Loading "
message:@"\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[_alertView addSubview:spinner];
[spinner startAnimating];
[_alertView show];
[_alertView performSelector:@selector(stopAlertActivity) withObject:self afterDelay:5.0];
}
-(void)stopAlertActivity
{ [spinner stopAnimating];
[_alertView dismissWithClickedButtonIndex:0 animated:YES];
}
ITS look like a transparent layer still running on screen,How can i close that?
example image....
for me that alert is not in screen now but the background is there in light blue color
CRASH REPORT
[UIAlertView stopAlertActivity]: unrecognized selector sent to instance 0x9ab5eb0
2013-08-02 12:20:43.822 AssamKart[5719:12203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIAlertView stopAlertActivity]: unrecognized selector sent to instance 0x9ab5eb0'
*** First throw call stack:
You need to change this line:
to:
The
stopAlertActivity
method is a method ofself
, not the alert view. And you can't pass an object to the selector becausestopAlertActivity
does not take any parameters.You should dismiss the alert view, not remove from superview, because it is attached to a semi transparent background. Call
stopAlertActivity
after the delay.you should really be using dispatch_after
You cannot dismiss the
alertView
by removing it from its superView. Instead you have to calldismissWithClickedButtonIndex:animated:
. This is the only way to dismiss it correctly, see the docs.In your case, I would define a method with the
alertView
as argument that executesdismissWithClickedButtonIndex:animated:
, and perform this method after the delay.