首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我正在尝试使用MWFeedParser显示MBProgressHUD的进度

我正在尝试使用MWFeedParser显示MBProgressHUD的进度
EN

Stack Overflow用户
提问于 2012-05-07 16:00:47
回答 3查看 15.1K关注 0票数 1

您好,我在过去的一个小时里一直在尝试使用环形行列式显示进度,但我似乎无法让它实现我想要的效果。它要么在我的表格视图加载内容之前就消失了,要么永远不会完全加载到进度条中。

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

代码语言:javascript
复制
- (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,因为它通过这些步骤,但我似乎不能这样做。接下来的步骤如下:

代码语言:javascript
复制
- (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];
}

如果有任何帮助,我将不胜感激!非常感谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-05-07 16:11:47

将通过一个很好的示例来帮助您解决问题。

票数 1
EN

Stack Overflow用户

发布于 2014-08-27 15:31:28

我想我得到了Year3000的答案

代码语言:javascript
复制
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

代码语言:javascript
复制
- (void)Uploadprogress:(float)progress
{
    self.HUD.progress = progress;
}

这对我很管用

票数 5
EN

Stack Overflow用户

发布于 2017-07-23 20:45:30

MBProgressHUDModeAnnularDeterminate

代码语言:javascript
复制
MBProgressHUD * hud = [MBProgressHUD HUDForView:self.view];

hud.mode = MBProgressHUDModeAnnularDeterminate

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

代码语言:javascript
复制
- (void)Uploadprogress:(float)progress
{
    self.HUD.progress = progress;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10478638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档