UIAlertView not dismissing - iphone

I'm using the following inside a button click or (IBAction)
- (IBAction)HistoryBtn:(id)sender {
self startReport];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//============================
so some long processing code
//============================
[self stopReport];
});
}
Where
-(void) startReport
{
alert = [[UIAlertView alloc] initWithTitle:#"Generating PDF" message:#" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[alert setDelegate:self];
[progress startAnimating];
[alert show];
}
-(void) stopReport
{
NSLog(#" Stop Called ");
[self.alert dismissWithClickedButtonIndex:0 animated:NO];
self.alert = nil;
NSLog(#" Stop Called ");
}
The problem is The AlertView popups up and I can see the button work, then StopReport IS called But the AlertView stays there How can I get the AlertView to go away
Thanks in advance

You must work with the UI only on the main thread.
- (IBAction)HistoryBtn:(id)sender {
self startReport];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//============================
so some long processing code
//============================
dispatch_async(dispatch_get_main_queue(), ^{
[self stopReport];
});
});
}

Related

loading symbol not appearing on button click

-(IBAction)addtocontacts:(id)sender
{
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = NSLocalizedString(#"Saving_data", #"");
//added my validation here
[self performSelectorInBackground:#selector(insertDetails) withObject:nil];
}
-(void) insertDetails
{
//save contact details in database
[HUD hide:YES];
UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:#"" message:#"Contact account details added" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertview show];
}
I have added loading symbol on SaveButton click.I am not getting loading symbol.How do I make it appear until I get alert message.
Add HUD on top most layer. Example if you have tableview on top of view. Then add it on tableview. In my case I am adding HUD on tableviews and its working fine
it is because you are instantly hiding the HUD in insertDetails.
-(IBAction)addtocontacts:(id)sender
{
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = NSLocalizedString(#"Saving_data", #"");
//added my validation here
[self performSelectorInBackground:#selector(insertDetails) withObject:nil];
}
-(void) insertDetails
{
//save contact details in database
// [HUD hide:YES]; remove it
UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:#"" message:#"Contact account details added" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertview show];
}
and instead download the newer version of MBProgressHUD and use the following Method
- (IBAction)addtocontacts:(id)sender {
// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.view addSubview:HUD];
// Regiser for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:#selector(myTask) onTarget:self withObject:nil animated:YES];
}
and implement the delegate method.
MBProgressHUDDelegate methods
- (void)hudWasHidden:(MBProgressHUD *)hud {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}

How to return keyboard for UITextField in UIAlertview in iphone?

I have one UIAlertView containing one UITextField with ok and cancel button. When I click on ok button i am calling webService. I want to return keyboard before calling webservice. Keyboard is not returning till response is not coming from webservice. Because of that half screen not visible to user during loading webservice. Here is my code which i did.
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Forgot Password" message:#" " delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
// Adds a username Field
alertEmailtextfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 29.0)];
alertEmailtextfield.layer.cornerRadius = 07.0f;
[alertEmailtextfield setBorderStyle:UITextBorderStyleRoundedRect];
alertEmailtextfield.placeholder = #"Enter Email";
[alertEmailtextfield setBackgroundColor:[UIColor whiteColor]];
alertEmailtextfield.autocapitalizationType =UITextAutocapitalizationTypeNone; //For Making Caps Off
[alertview addSubview:alertEmailtextfield];
[alertview show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
if ([alertEmailtextfield.text length] != 0) {
if (![self validEmail:alertEmailtextfield.text]) {
[AlertView UIAlertView:#"Enter email is not correct"];
}else{
//[alertEmailtextfield resignFirstResponder];
[NSThread detachNewThreadSelector:#selector(startSpinner) toTarget:self withObject:nil];
Boolean isForgotPassword = [serverConnection forgotPassword:alertEmailtextfield.text];
if (isForgotPassword) {
NSLog(#"Mail is send");
[AlertView UIAlertView:#"New password is send to your mail"];
[spinner stopAnimating];
}else{
[AlertView UIAlertView:#"User does not exist"];
[spinner stopAnimating];
}
}
}else{
[AlertView UIAlertView:#"Text Field should not be empty"];
}
}
}
Please if any one knows how to return keyboard in UIAlertView's UITextField, help me.
Your UI is stuck waiting for your webservice to complete. Call your webservice in a background thread your problem will be solved.
[self performSelectorInbackgroundThread:#selector(yourWebservice)];
Might be u are doing both task (webservice call and keyboard resinging) in same main thread so untill ur data is not loading from server keyboard is not resign from view. call weservice method in background thread like.
-(void)alertView:(CustomAlert *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[textField resignFirstResponder];
UPdate
[self performSelectorInBackground:#selector(yourWebservice) withObject:nil];
}

Disable Alertview Programmatically

I want to display a activity indicator in AlertView with no buttons, I want to disable it when activity indicator stops animating.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];
[alert show];
[progress release];
Then to dismiss the alert view and spinner: (you'll need to make the alert view a member)
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
Just call dismissWithClickedButtonIndex:animated: method for UIAlertView
[alertView dismissWithClickedButtonIndex:0 animated:YES];
Just call the:
[theAlertViewInstance dismissWithClickedButtonIndex: 0 animated:YES];
This should do, what you need.

iphone-UIAlertview-UIIndicatorview

i Am New In Iphone development. i have one form in which for display data I am calling a webservice. When that service is called it parses from other file, And Page Navigates To 'Send Page' In Which These Data Is Displayed In a UITableview.
i am also using uiAtertview And UIIndicatorview Both For Displaying that the process is going. But Problem Is When I Click On Button I Call UIAtertView + UIIndicator But It Is Not getting Displayed And Data is Also Not getting Displayed,,,
My Code Is
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Configuring Preferences\nPlease Wait.." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil,nil];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
self.ResultPage = [[ResultPage alloc] init];
self.title=#" Search ";
// Here My Webservice Is Call From Another ViewController Class And That Class Display Data //InTo UITableVIew
[self.ResultPage GetSearchResult:StrBookId : txtFPrice.text :txtTprice.text];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[self.navigationController pushViewController: _ResultPage animated:YES];
Please Suggest Me....
Thanx
You can add activity indicator in alert view and show that alert view when you call web service.I also do the same when I call webservice. it locks the view so that the user cannot click anything and look wise also seems to be fine and indicating user that something is going in process.
in .h file
UIAlertView *progressAlert;
in .m file
-(void)showAlertMethod
{
NSAutoreleasePool *pool1=[[NSAutoreleasePool alloc]init];
progressAlert = [[UIAlertView alloc] initWithTitle:#"Uploading please wait...\n" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
CGRect alertFrame = progressAlert.frame;
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.frame = CGRectMake(135,alertFrame.size.height+55, alertFrame.size.width,30);
activityIndicator.hidden = NO;
activityIndicator.contentMode = UIViewContentModeCenter;
[activityIndicator startAnimating];
[progressAlert addSubview:activityIndicator];
[activityIndicator release];
[progressAlert show];
[pool1 release];
}
-(void)dismissAlertMethod
{
NSAutoreleasePool *pool2=[[NSAutoreleasePool alloc]init];
[progressAlert dismissWithClickedButtonIndex:0 animated:YES];
[pool2 release];
}
call the method according to your requirements.
I call the methods in this way:-
[NSThread detachNewThreadSelector:#selector(showAlertMethod) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:#selector(dismissAlertMethod) toTarget:self withObject:nil];

Create popup animation

How to create a pop up animation on iPhone? I want show my uiview as a popup view, like uialertview design.
- (void) killHUD
{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
[alertView release];
alertView = nil;
}
- (void)presentSheet:(NSString *)message withFrame:(CGRect)frame
{
if(!alertView)
{
alertView = [[CustomAlertView alloc] initWithFrame:frame onView:self.window];
alertView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
[alertView setNeedsDisplay];
[alertView setText:message];
[alertView show];
}
}
You can use these functions creaed by me to show an hide the loading animation popup..
Happy Coding..