-(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;
}
Related
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];
});
});
}
Ha ii,everybody ,i am doing a reader application ,in my app there is a note syncing option to googledoc,so the user write the note in a note-view and saved ,the saved note is displayed or saved in another view controller in UItableview .My requirement is when the user tapped the gDoc button it automatically wants to sync all the notes from the UiTableView to GDoc.I just saved the notes by this code when the save button pressed
-(IBAction)savedNote
{
[delegate.indexArray addObject:[NSString stringWithFormat:#"%# %#:%#",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
[delegate.notesArray addObject:textVieww.text];
[notes setValue:textVieww.text forKey:[NSString stringWithFormat:#"%# %#:%#",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
NSString *DataPath = [Malayalam_BibleAppDelegate getPath];
[delegate.data writeToFile:DataPath atomically:YES];
proAlertView *alert = [[proAlertView alloc]initWithTitle:#"NOTES" message:#"Notes Saved" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert setBackgroundColor:[UIColor colorWithRed:0.255 green:0.218 blue:0.185 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
[alert show];
[alert release];
}
-(IBAction)_clickbtngoogledocsync:(id)sender
{
Googledocmainpage *detailViewController = [[Googledocmainpage alloc] initWithNibName:#"Googledocmainpage" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.localStringtextnote = localStringtextnote;//i want to pass these note to googledocmainpage as localstring
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
UIView *langview = (UIView *)[self.view viewWithTag:120];
//ViewWithTag Number should be same as used while allocating
[langview removeFromSuperview];
/* [self.view addSubview:syncView];
UIView *popView = (UIView *)[self.view viewWithTag:106];
//ViewWithTag Number should be same as used while allocating
[popView removeFromSuperview];*/
}
How to do this.Thanks in advance.
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];
Is there an easy way to display a wait animation in the iPhone sdk. I have a screen that will take a few seconds to load, and I'd like to give the user some feedback that something is happening. Any suggestions?
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
or
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
will do the trick!
edit: Found this one in an older project, client requested an indicator with better visibility:
-(void)invokeMegaAnnoyingPopup
{
self.megaAlert = [[[UIAlertView alloc] initWithTitle:#"Please wait..."
message:nil delegate:self cancelButtonTitle:nil
otherButtonTitles: nil] autorelease];
[self.megaAlert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(self.megaAlert.bounds.size.width / 2,
self.megaAlert.bounds.size.height - 45);
[indicator startAnimating];
[self.megaAlert addSubview:indicator];
[indicator release];
}
-(void)dismissMegaAnnoyingPopup
{
[self.megaAlert dismissWithClickedButtonIndex:0 animated:YES];
self.megaAlert = nil;
}
You would of course need a UIAlertView *megaAlert; defined in your class.
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..