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";
}
Related
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];
}
I'm trying to add a custom view to an UITableView created with code from an UITableViewController. This view is a HUD window with a message (MBProgressHUD)
So I have a method reload() called from the overridden initWithStyle() method and from the refresh button of the table:
- (void) reload {
HUD = [[MBProgressHUD alloc] initWithView:self.tableView];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Downloading";
[HUD showWhileExecuting:#selector(reloadWithHUD) onTarget:self withObject:nil animated:YES];
}
The first time, the HUD appears behind the table lines. Once loaded, when I press reload button, the view shows as expected. The initWithStyle() method (with some code removed for clarity) is:
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self) {
// Custom initialization.
self.title = NSLocalizedString...
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle ... action:#selector(reload)];
self.navigationItem.rightBarButtonItem = button;
[button autorelease];
[self reload];
}
return self;
}
I've tried changing the HUD view with a simple UILabel, with the same result.
I also changed the code to call reload() from viewDidLoad(), but doesn't work either. How can I resolve this issue? Thank you very much.
EDIT : to clarify this, here is a possible solution to this problem. Many thanks to Bill Brasky for his help:
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[[[UIApplication sharedApplication] keyWindow] addSubview:HUD];
Here is what I'm doing in my app with an almost identical application.
You need to add it to the main view WINDOW, not the tableView.
HUD = [[MBProgressHUD alloc] initWithView:self.view.window];
[self.view.window addSubView:HUD];
My project is based on IOS 7
This helps me
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];