MBProgressHUD's Frame is Faulty - iphone

I am following the exact code provided with the sample project. Here's what I get usually:
But not always. Sometimes it runs as it should. The iPhone I am developing is running iOS 5.0.1
Thanks!
HUD = [[MBProgressHUD alloc]initWithView:self.view.window];
[self.view.window addSubview:HUD];
HUD.delegate = self;
[HUD showWhileExecuting:#selector(loadFriends) onTarget:self withObject:nil animated:YES];

Try to initialize and add it without the 2 instances of .window, like this:
HUD = [[MBProgressHUD alloc]initWithView:self.view];
HUD.mode = MBProgressHUDModeDeterminate;
HUD.delegate = self;
[self.view addSubview:HUD];
[HUD showWhileExecuting:#selector(loadFriends) onTarget:self withObject:nil animated:YES];

It turned out to be an incompatibility issue between MBProgressHud and iOS 5. I couldn't get it to work, not in each run at least. So I ended up not using it.

Related

MBProgressHUD hide after receive response from server

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;

Can't show MBProgressHUD

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];

performSelector: withObject: afterDelay not executing for MBProgressHUD

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];
}

MBProgressHUD call from ViewDidLoad

I call my rss parser from MBProgressHUD and at the moment it's in viewdidappear and it works, however I want it in viewdidload so when I go back it doesn't reload it - however when I move it in to viewdidload it runs the process but not the MBProgressHUD.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Results";
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[self.view.window addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Loading";
HUD.detailsLabelText = #"updating data";
//Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:#selector(loadResults) onTarget:self withObject:nil animated:YES];
}
Any ideas?
Thanks, Tom
In viewDidLoad method, the self.view will be loaded without its superview and window. For Example, self.view.superview will be loaded in viewWillAppear method, then self.view.window will be loaded in viewDidAppear method. That's why the [self.view.window addSubview:HUD] won't be happened in viewDidLoad, but the [self.view addSubview:HUD] works.
Try below code, its working fine at my end.
- (void)viewDidLoad {
[super viewDidLoad];
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = #"Loading";
HUD.detailsLabelText = #"updating data";
}

MBProgressHUD and performselector problem - iphone

i wrote below code to MBProgressHUD:
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = NSLocalizedString(#"Loading Workbench", nil);
HUD.detailsLabelText = NSLocalizedString(#"please wait", nil);
[HUD showWhileExecuting:#selector(loadWorkbench) onTarget:self withObject:nil animated:YES];
and in loadWorkbench method i wrote the code like:
[self performSelector:#selector(CallPrivateKwikis) withObject:nil afterDelay:0.1];
but from here CallPrivateKwikis is never called. i am unable to find the problem.
can any one of you please help on this.
Thanks in advance.
[self performSelector:#selector(CallPrivateKwikis:) withObject:nil afterDelay:0.1];
Add the colon at the end of CallPrivateKwikis.
Use HUD = [[MBProgressHUD alloc]initWithview:self.view]];
insted of
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; then ur problem will be solved