Reputation: 2185
well I have my RSS application running perfect, and now i'm trying to add some indicator with MBProgressHUD.
I implement this code in the View Controller under ViewDidLoad
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Loading";
[HUD show:YES];
so far so good. the indicator is working but of course never disappearing. I am a newbie, I tried to add to my [HUD hide:yes] in certain parts of the implementation file but it's not working . how can I hide the indicator when the data finish to load ? here is my implementation file.
@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
Upvotes: 1
Views: 1737
Reputation: 3764
to show:
[[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES] setLabelText:@"Loading"];
to hide:
[MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
Upvotes: 1
Reputation: 1534
May I recommend using SVProgressHUD
instead?
https://github.com/samvermette/SVProgressHUD
You just have to call [SVProgressHUD show]
and [SVProgressHUD dismiss]
Upvotes: 5