你好我一直在嘗試使用最後一小時的環形確定來顯示進度,我似乎無法讓它做我想做的事情。它要麼在我的表格視圖加載內容之前消失,要麼從未完全加載到進度條。我試圖使用MWFeedParser顯示MBProgressHUD的進度
在我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];
}
我將不勝感激任何幫助!非常感謝你!
謝謝你,但我看過了這一點,該示例並不完全告訴我怎麼更新進度條。看到我是新手進度條,我不知道如何根據我的需要更新它,而該示例僅使用循環。 – Year3000