Morkrom
Morkrom

Reputation: 578

UIRefreshControl crashes while refreshing Tableview Controller

I can't refresh my TVC. It crashes when I drag down to refresh. The icon is there, but then it quits. I'm sure its something simple. There are similar questions out there which have not been considered.

Taken from my viewDidLoad method body:

refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self
                   action:@selector(refreshInvoked:forState:)
         forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:refreshControl];

refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:title
                                                            attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:13.0]}];
[self refreshFeed];

Which refers to:

-(void)refreshFeed 
{
   RSSLoader* rss = [[RSSLoader alloc] init];    
   [rss fetchRssWithURL:feedURL
            complete:^(NSString *title, NSArray *results) {
                dispatch_queue_t downloadQueue = dispatch_queue_create("downloader",NULL);
                dispatch_async(downloadQueue, ^{
                _objects = results;
                    [self.tableView reloadData];
                //completed fetching the RSS
                dispatch_async(dispatch_get_main_queue(), ^{
     //               [(HeaderView*)self.tableView.tableHeaderView setText:title];
                    // [(ArticleItem*)self.tableView.]
                });
                });
    }];
}

Upvotes: 2

Views: 1370

Answers (2)

Peter Lapisu
Peter Lapisu

Reputation: 20975

UIRefreshControl is not meant to be added as subview... doing so will get you some trouble and you need to unregister its target on VC dealloc... else you might get some issues, when the UIRefreshControl calls your dead VC (as it doesn't keep a weak or strong reference to your VC)

Upvotes: 4

iDev
iDev

Reputation: 23278

Change your action method to:

[refreshControl addTarget:self
                   action:@selector(refreshFeed)
         forControlEvents:UIControlEventValueChanged];

Looks like you were pointing to refreshInvoked:forState: which was not present in self.

Upvotes: 3

Related Questions