MBProgressHUD与表查看如何隐藏HUD?

 七里汀 发布于 2023-01-30 16:31

好吧,我的RSS应用程序运行完美,现在我正在尝试使用MBProgressHUD添加一些指标.

我在ViewDidLoad下的View Controller中实现了这段代码

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

[HUD show:YES];

到现在为止还挺好.该指标正在发挥作用,但当然永远不会消失.我是新手,我试图在实现文件的某些部分添加到我的[HUD隐藏:是]但是它不起作用.如何在数据加载完成后隐藏指示器?这是我的实现文件.

    @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

Sean.. 5

我可以推荐使用SVProgressHUD吗?

https://github.com/samvermette/SVProgressHUD

你只需要打电话[SVProgressHUD show][SVProgressHUD dismiss]

1 个回答
  • 我可以推荐使用SVProgressHUD吗?

    https://github.com/samvermette/SVProgressHUD

    你只需要打电话[SVProgressHUD show][SVProgressHUD dismiss]

    2023-01-30 16:33 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有