I wan to to show a message using the MBProgressHUD during the uploading via NSURL string. So i code that:
MBProgressHUD *hud1 = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud1.labelText = #"sending info ...";
hud1.minShowTime =10.0;
NSURL *url =[NSURL URLWithString:self.urlToUpload];
the 10 second time is in order to wait some time i want user wait. It works, but I would show another message when the first desappear. Using another:
MBProgressHUD *hud2 = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud2.labelText = #"SENT!";
hud2.minShowTime =2.0;
it is not useful, because this message overlaps the first one.
Any tips about that?
I would remove the first HUD in your -connectionDidFinishLoading method or wherever you get notification that the string has been uploaded successfully.
[MBProgressHUD hideHUDForView:self.view animated:YES];
Then you can add your next HUD for 1-2 seconds. By just adding it via a specific time, there is no way to accurately remove the first HUD before the next one shows.
This was taken from the MBProgressHUD demo project. I would use this to display your timed completion HUD.
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
// The sample image is based on the work by http://www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]] autorelease];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = #"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
+(void)toast:(NSString*) str view:(UIView*)view delegate:(id)delegate type:(IconType)type{
[MBProgressHUD hideHUDForView:view animated:YES];
MBProgressHUD * HUD = [[MBProgressHUD alloc] initWithView:view];
[view addSubview:HUD];
NSString* strImage;
switch (type) {
case kNone:
strImage=nil;
break;
case kOK:
strImage=#"37x-Checkmark.png";//NSString stringWithFormat:#"%#",
break;
case kError:
strImage=#"ic_cancel_white_24dp.png";//NSString stringWithFormat:#"%#",
break;
default:
break;
}
HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:strImage] ];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = delegate;
HUD.labelText = str;
HUD.userInteractionEnabled = NO;
[HUD show:YES];
[HUD hide:YES afterDelay:1.5f];
}
Related
My MBProgressHUD is not show after i removing from superview. when I first time remove superview after that I almost sow but does not visible.
my code is
if(condition)
{
HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]];
[HUD bringSubviewToFront:HUD];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = #"Unfollowed";
[HUD hide:YES afterDelay:0.5];
}
[HUD hide:YES];
[HUD removeFromSuperViewOnHide];
after that I show once again it
[HUD show:YES];
but this method don't display it. please help me
I have list of song titles displayed in uitableview along with "Buy" button.when that button is tapped i am showing MBProgressHUD.But sometimes it is not being displayed.also it disables the user-interaction as it is in the below code.
But why it is not displaying the MBProgressHUD sometimes?
Please let me know, Thanks a lot.
Below is the code
-(void) buySong:(UIButton *)button
{
self.view.userInteractionEnabled = NO;
self.navigationController.navigationBar.userInteractionEnabled = NO;
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = #"Proessing...";
hud.yOffset = -80;
UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
NSIndexPath *indexPath = [[self tblViewChildrenPoems] indexPathForCell:cell];
PSSongTags *songTags = [self.songsArray objectAtIndex:indexPath.row];
[ [PurchaseViewController sharedPurchaseManager] startPurchase:songTags];
}
Try this code may be helped you...
In your .h file import the .
#import "MBProgressHUD.h"
the set the delegate .
MBProgressHUDDelegate
After
MBProgressHUD *HUD;
in your .m file // Add this code where you want display ...
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Authorizing...";
[HUD show:YES];
and when your process end use for hide ..
[HUD Hide:YES];
and set hide delegate in your m file also..
- (void)hudWasHidden:(MBProgressHUD *)hud {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}
Happy coding...
i want to hide MBProgressHUD when i'm receive xml response from server and i use httpconnection to get xml from server,,anybody help me?? thx before..
follow this steps to hide the ProgressHUD
take a class level variable for hud
MBProgressHUD *hud;
then make two functions
-(void)showProgress
{
if (!hud)
hud = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:hud];
//hud.delegate = self;
hud.labelText = #"Loading...";
[hud show:YES];
}
-(void)hideProgress
{
[hud hide:YES];
[hud removeFromSuperview];
[hud release];
hud=nil;
}
call showProgress() when you initiate the network hit
and call hideProgress() when callback of success or failure called.
You should retain an instance of MBProgressHUD in the class or the delegate that is getting the data from the server,
in the interface
{
MBProgressHUD *hud;
}
do [hud show..] when the progress starts and
[hud hide] when it finishes.
I think you use HUD delgete for hideen
try this:-
-(void)hudWasHidden // for remove the hud
{
[HUD removeFromSuperview];
}
call the Hud
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.graceTime = .1;
HUD.navigationBar = self.navigationController.navigationBar;
HUD.labelFont = [UIFont fontWithName:#"Arial" size:14];
HUD.delegate = self;
[self.view addSubview:HUD];
[HUD showWhileExecuting:#selector(yourFunction name:) onTarget:self withObject:nil animated:YES];
in .h File use this
MBProgressHUD *HUD;
In here said that using MBProgressHUD is easy.
But I can't make it.
Here my code:
- (IBAction)save{
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
[HUD show:YES];
NSString *title = [page stringByEvaluatingJavaScriptFromString:#"document.title"];
SavePageAs *savePage = [[SavePageAs alloc] initWithUrl:self.site directory:title];
[savePage save];
[HUD hide:YES];
}
The progress indicator is not showing during savePage save method run, but shows after the page completely saved (the indicator is shown for less than 1 second).
I also tried this way:
- (IBAction)save {
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Saving...";
[HUD showWhileExecuting:#selector(performFetchOnMainThread) onTarget:self withObject:nil animated:YES];
}
- (void) savingPage{
NSString *title = [page stringByEvaluatingJavaScriptFromString:#"document.title"];
SavePageAs *savePage = [[SavePageAs alloc] initWithUrl:self.site directory:title];
[savePage save];
}
-(void) performFetchOnMainThread {
[self performSelectorOnMainThread:#selector(savingPage) withObject:nil waitUntilDone:YES];
}
But still no luck. Anyone let me know where I'm lack here?
P.S: savePage save is saving all website contents to local directory. I wish once the saving is complete the progressHUD disappear.
Thanks
Try allocation of HUD on the viewWillAppear: instead of -(IBAction)save because sometimes allocation takes up the whole time and by the time it allocates whole task is finished.
Copy Following links to viewWillAppear: and remove them from -(IBAction)save
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Saving...";
EDIT: Keep allocations on viewWillAppear: and change code as shown below:
- (IBAction)save {
[NSThread detachNewThreadSelector:#selector(showHUD) withObject:nil];
[self performSelectorOnMainThread:#selector(savingPage) withObject:nil waitUntilDone:YES];
}
- (void) savingPage{
NSString *title = [page stringByEvaluatingJavaScriptFromString:#"document.title"];
SavePageAs *savePage = [[SavePageAs alloc] initWithUrl:self.site directory:title];
[savePage save];
[HUD hide:YES];
}
-(void)showHUD {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[HUD show:YES];
[pool release];
}
What this will do is create a separate thread to display HUD as main thread is being engaged by savingPage method.
If this too doesn't work, then just change waitUntilDone:YES to waitUntilDone:NO
Note: As per Apple documentation
Important If you use Automatic Reference Counting (ARC), you cannot
use autorelease pools directly. Instead, you use #autoreleasepool
blocks instead. For example, in place of:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init;
// Code benefitting from a local autorelease pool.
[pool release];
you would write:
#autoreleasepool {
// Code benefitting from a local autorelease pool.
}
#autoreleasepool blocks are more efficient than using an instance of
NSAutoreleasePool directly; you can also use them even if you do not
use ARC.
Hope this helps.
check out this code
- (IBAction)save{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.graceTime = .1;
HUD.navigationBar = self.navigationController.navigationBar;
HUD.labelText = #"Saving";
HUD.delegate = self;
[self.view addSubview:HUD];
[HUD showWhileExecuting:#selector(savingPage) onTarget:self withObject:nil animated:YES];
}
- (void) savingPage{
NSString *title = [page stringByEvaluatingJavaScriptFromString:#"document.title"];
SavePageAs *savePage = [[SavePageAs alloc] initWithUrl:self.site directory:title];
[savePage save];
}
when saveingpage method will be completed MBProgressHUD delegate will be called so implement this delegate method in your class,This will remove HUD from your view
-(void)hudWasHidden
{
[HUD removeFromSuperview];
}
Try changing the HUD allocation lines to
HUD = [MBProgressHUD showHUDAddedTo: self.navigationcontroller.view animated:YES];
HUD.labelText....
And then in your saving method you can have
[MBProgressHUD hideHUDForView:self.navigationcontroller.view animated:NO];
I have the following method for a MBProgressHUD:
[progressHUD performSelector:#selector(hide:)
withObject:[NSNumber numberWithBool:YES]
afterDelay:kMessageHidingDelay];
the delay is 2.0 here, however it's not calling hide after 2.0 seconds. I tried to put a breakpoint in the hide function and it's not getting there. Any idea? Here's the full code:
progressHUD = [[MBProgressHUD alloc] initWithView:viewToAttach];
// Add HUD to screen
[viewToAttach addSubview:progressHUD];
progressHUD.labelText = #"Logging In";
progressHUD.removeFromSuperViewOnHide = YES;
// Show the HUD while the provided method executes in a new thread
[progressHUD show:YES];
May be try to perform selector on Main thread (all UI changes must be done on main thread)?
performSelectorOnMainThread:
you have to hide the MBProgressHud
[progressHUD hide:YES];
To Show MBProgressHUD Use this Code:-
HUD = [[MBProgressHUD alloc] init];
[self.view addSubview:HUD];
HUD.delegate = self;
[HUD showWhileExecuting:#selector(myTask) onTarget:self withObject:nil animated:YES];
where myTask is
- (void)myTask
{
"Your Code"
}
And too Hide the MBProgressHud
- (void)hudWasHidden:(MBProgressHUD *)hud
{
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
HUD = nil;
}
And If you Want to Show Hud With Your CostomView Then Use This Code
HUD = [[MBProgressHUD alloc] init];
[self.view addSubview:HUD];
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Your Image Name.png"]] autorelease];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = #"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}