I'm Trying to Show Progress With MBProgressHUD using MWFeedParser

15,093

Solution 1

MBProgressHUD will help you out along with a good example.

Solution 2

I think i got answer for Year3000

self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.HUD];
self.HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
self.HUD.delegate = self;
[self.HUD show:YES];

//catch your progress and set it to HUD

- (void)Uploadprogress:(float)progress
{
    self.HUD.progress = progress;
}

This works for me

Solution 3

MBProgressHUDModeAnnularDeterminate !

MBProgressHUD * hud = [MBProgressHUD HUDForView:self.view];

hud.mode = MBProgressHUDModeAnnularDeterminate

then update your hud value: (values 0.0 to 1.0)

- (void)Uploadprogress:(float)progress
{
    self.HUD.progress = progress;
}
Share:
15,093
Year3000
Author by

Year3000

Updated on November 22, 2022

Comments

  • Year3000
    Year3000 over 1 year

    Hello I've been trying to display progress using the annular determinate for the last hour and I can't seem to make it do what I want. It either disappears way before my table view is loaded with content or never loads to progress bar fully.

    In my viewDidLoad method I show it while starting to run MWFeedParser like this:

    - (void)viewDidLoad {
    
    [super viewDidLoad];
    
    // Parse
    NSURL *feedURL = [NSURL URLWithString:@"http://myurl.com"];
    feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
    feedParser.delegate = self;
    feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
    feedParser.connectionType = ConnectionTypeAsynchronously;
    [feedParser parse];
    
    // Display HUD
    [super viewDidLoad];
    
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    HUD.labelText = @"Loading";
    HUD.detailsLabelText = @"Just relax";
    HUD.mode = MBProgressHUDModeAnnularDeterminate;
    [self.view addSubview:HUD];
    
    [HUD showWhileExecuting:@selector(feedParserDidStart:) onTarget:self withObject:nil animated:YES];
    
    }
    

    After I call my parser it then runs through 5 different steps, I want to update my HUD as it goes through these steps, but I can't seem to do that. The next steps are these:

    - (void)feedParserDidStart:(MWFeedParser *)parser {
    NSLog(@"Started Parsing: %@", parser.url);
    
    float stepsDone = 0.20;    
    HUD.progress = stepsDone;
    
    }
    
    - (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info {
    NSLog(@"Parsed Feed Info: “%@”", info.title);
    
    float stepsDone = 0.40;    
    HUD.progress = stepsDone;
    
    
    }
    
    - (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
    NSLog(@"Parsed Feed Item: “%@”", item.title);
    if (item) [parsedItems addObject:item]; 
    
    float stepsDone = 0.60;    
    HUD.progress = stepsDone;
    }
    
    - (void)feedParserDidFinish:(MWFeedParser *)parser {
    NSLog(@"Finished Parsing%@", (parser.stopped ? @" (Stopped)" : @""));
    [self updateTableWithParsedItems];
    
    float stepsDone = 0.80;    
    HUD.progress = stepsDone;
    }
    
    - (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error {
    NSLog(@"Finished Parsing With Error: %@", error);
    if (parsedItems.count == 0) {
        // Failed but some items parsed, so show and inform of error
    
    }
    
    //Update Table
    [self updateTableWithParsedItems];
    }
    
    - (void)updateTableWithParsedItems {
    self.itemsToDisplay = [parsedItems sortedArrayUsingDescriptors:
                           [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"date" 
                                                                                ascending:NO] ]];
    self.tableView.userInteractionEnabled = YES;
    self.tableView.alpha = 1;
    [self.tableView reloadData];
    
    float stepsDone = 1.0;    
    HUD.progress = stepsDone;
    
    [HUD hide:YES afterDelay:1];
    }
    

    I would appreciate any help! Thank you very much!

  • Year3000
    Year3000 almost 12 years
    thank you, but I've looked over that and the example doesn't quite tell me how to update the progress bar. Seeing that I'm new to progress bars I don't know how to update it based on my needs, and the example only uses a loop.