MBProgressHUD与表查看如何隐藏HUD?

时间:2014-01-29 12:13:38

标签: ios objective-c ios-simulator

我的RSS应用程序运行完美,现在我正在尝试使用MBProgressHUD添加一些指示器。

我在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

2 个答案:

答案 0 :(得分:5)

我建议您改用SVProgressHUD吗?

https://github.com/samvermette/SVProgressHUD

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

答案 1 :(得分:1)

显示:

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

隐藏:

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