1

您好,在过去的一个小时里,我一直在尝试使用环形确定来显示进度,但我似乎无法让它做我想做的事情。它要么在我的表格视图加载内容之前消失,要么永远不会完全加载到进度条。

在我的 viewDidLoad 方法中,我在开始运行 MWFeedParser 时显示它,如下所示:

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

}

在我调用我的解析器之后,它会运行 5 个不同的步骤,我想在它通过这些步骤时更新我的​​ HUD,但我似乎无法做到这一点。接下来的步骤是:

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

我将不胜感激任何帮助!非常感谢你!

4

3 回答 3

5

我想我得到了 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];

//捕捉你的进度并将其设置为HUD

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

这对我有用

于 2014-08-27T07:31:28.177 回答
1

MBProgressHUD将通过一个很好的示例帮助您。

于 2012-05-07T08:11:47.177 回答
1

MBProgressHUDMode环形确定

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

hud.mode = MBProgressHUDModeAnnularDeterminate

然后更新您的 hud 值:(值 0.0 到 1.0)

- (void)Uploadprogress:(float)progress
{
    self.HUD.progress = progress;
}
于 2017-07-23T12:45:30.327 回答