chpwn/PullToRefreshView — Issue #8: Pull-to-refresh window doesn't disappear
Author: andiaut
Created: 2011-11-06 12:37:12+00:00
State: open

I implemented everything into my rss reader, but after bulling the tableview down, the loading window doesn't disappear anymore.

#import "RssFunViewController.h"
#import "BlogRssParser.h"
#import "BlogRss.h"
#import "GYSAAppDelegate.h"

@implementation RssFunViewController

@synthesize rssParser = _rssParser;
@synthesize tableView = _tableView;
@synthesize appDelegate = _appDelegate;
@synthesize toolbar = _toolbar;

-(void)toolbarInit{
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(reloadRss)];
refreshButton.enabled = NO;
NSArray *items = [NSArray arrayWithObjects: refreshButton, nil];
[self.toolbar setItems:items animated:NO];
[refreshButton release];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self toolbarInit];
_rssParser = [[BlogRssParser alloc]init];
self.rssParser.delegate = self;
[[self rssParser]startProcess];
pull = [[PullToRefreshView alloc] initWithScrollView:_tableView];
[pull setDelegate:self];
[_tableView addSubview:pull];
}

// called when the user pulls-to-refresh
- (void)pullToRefreshViewShouldRefresh:(PullToRefreshView *)view {
[[self tableView]reloadData];
}

- (void)finishedLoading {
//reload the table view
[[self tableView]reloadData];
}

-(void)toggleToolBarButtons:(BOOL)newState{
NSArray *toolbarItems = self.toolbar.items;
for (UIBarButtonItem *item in toolbarItems){
item.enabled = newState;
}
}

- (void)processCompleted{
//reload the table view
[self toggleToolBarButtons:YES];
[[self tableView]reloadData];
}

//Delegate method for blog parser will get fired when the process is completed

-(void)processHasErrors{
//Might be due to Internet
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Achtung!" message:@"Leider ist es im Moment nicht möglich eine Verbindung zum Internet herzustellen."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
[self toggleToolBarButtons:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[[self rssParser]rssItems]count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
if(nil == cell){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease];
}
cell.textLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]];
[self.appDelegate loadNewsDetails];
[_tableView deselectRowAtIndexPath:indexPath animated: YES];
}

- (void)viewDidUnload {
pull=nil;
[PullToRefreshView release];
}

- (void)dealloc {
[_appDelegate release];
[_toolbar release];
[_tableView release];
[_rssParser release];
[PullToRefreshView release];
[super dealloc];
}

@end