MBProgresshud带有表查看如何隐藏HUD



好吧,我的RSS应用程序运行完美,现在我试图用mbprogresshud添加一些指标。

i在ViewDidload下的View Controller中实现此代码

 HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Loading";
[HUD show:YES];

到目前为止一切都很好。指标正在起作用,但当然从未消失。我是一个新手,我试图在实现文件的某些部分中添加到我的[HUD hide:yes]中,但它不起作用。当数据完成加载时,如何隐藏指示器?这是我的实现文件。

    @implementation ListadoArticulosViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // HUD setting 
    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];
    HUD.labelText = @"Loading";
    [HUD show:YES];
     NSURL *feedURL = [NSURL URLWithString:@"http://girlsonlyapp.wordpress.com/feed/"];
    feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
    feedParser.delegate = self;
    feedParser.feedParseType = ParseTypeFull;
    feedParser.connectionType = ConnectionTypeAsynchronously;
    listadoArticulos = [[NSMutableArray alloc] init];
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(cargaArticulos) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refreshControl;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self cargaArticulos];
}
- (void)cargaArticulos {
    [feedParser parse];
}
#pragma mark MWFeedParserDelegate
- (void)feedParserDidStart:(MWFeedParser *)parser {
    NSLog(@"Comienza el parseo");
    // We emptied the list of items to avoid accumulating
   // in subsequent calls
    [listadoArticulos removeAllObjects];
    // We put up the refresh Control
    [self.refreshControl beginRefreshing];
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info {
    // Once we have recovered the items we
  // The name of the blog as the view controller title
    self.title = @"titles";
 }
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
    // Add the item to the array downloaded
    [listadoArticulos addObject:item];
}
- (void)feedParserDidFinish:(MWFeedParser *)parser {
     // Como ya ha finalizado el parse, denemos el parser
    [feedParser stopParsing];
    // Detenemos el refresh control
    [self.refreshControl endRefreshing];
    // Refrescamos el table view
    [self.tableView reloadData];
    // trying to  do something
}
- (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error {
    NSLog(@"Ha ocurrido un error al tratar de recuperar los artículos.");
    // En caso de que este funcionando el refresh control y
    // se produzca un error, lo detenemos.
    if ([self.refreshControl isRefreshing]) {
        // Detenemos el refresh control
        [self.refreshControl endRefreshing];
    }
}
#pragma mark UITableViewDelegate / UITableViewDataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ArticuloCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ArticuloCell"];
    MWFeedItem *item = [listadoArticulos objectAtIndex:indexPath.row];
    cell.titulo.text = item.title;
    // Guy Cohen - this is the second label that we can customize , orignally it was link, but it changed
    // it to summary
    cell.descripcion.text = item.summary;
        return cell;
    }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return listadoArticulos.count;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    ArticuloCell *celda = (ArticuloCell *)sender;
    MWFeedItem *item = [listadoArticulos objectAtIndex:[self.tableView indexPathForCell:celda].row];
    DetalleViewController *detalleVC = (DetalleViewController *)segue.destinationViewController;
    [detalleVC setItem:item];
 }
@end

我可以建议使用 SVProgressHUD吗?

https://github.com/samvermette/svprogresshud

您只需要致电[SVProgressHUD show][SVProgressHUD dismiss]

显示:

[[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES]  setLabelText:@"Loading"];

隐藏:

[MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];

最新更新