r-plus / AAPullToRefresh

All around pull to refresh library.
Other
153 stars 37 forks source link

Memory / deallocated error in NavigationController #2

Open trainerleipzig opened 10 years ago

trainerleipzig commented 10 years ago

I have a navigation controller based application. At the first view there exist a button who push another ViewController or TableViewController to the navigation controller stack. This ViewController / TableViewController use the AAPullToRefresh. If I go back to the main root controller, I get the follow error message:

"An instance 0x99fca00 of class UITableView was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: <NSKeyValueObservationInfo 0x8ba4790> ( <NSKeyValueObservance 0x8bcffe0: Observer: 0x8bcc2d0, Key path: contentOffset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x8cd3d80> <NSKeyValueObservance 0x8bd0040: Observer: 0x8bcc2d0, Key path: contentSize, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x8cd5970> <NSKeyValueObservance 0x8bd00e0: Observer: 0x8bcc2d0, Key path: frame, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x8cd5fc0> )"

If I need a ViewController with ScrollView it's the same. Only the word "UITableView" replaced by "UIScrollView". The message replicate with every new push of the controller. What can I do?

arielpollack commented 10 years ago

add this method to AAPullToRefresh.m

-(void) dealloc
{
    @try
    {
        [self.scrollView removeObserver:self forKeyPath:@"contentOffset"];
        [self.scrollView removeObserver:self forKeyPath:@"contentSize"];
        [self.scrollView removeObserver:self forKeyPath:@"frame"];
    }
    @catch (NSException *exception)
    { 
    }
}
xzenon commented 10 years ago

Adding -(void) dealloc {..} did not help me with this issue. After I switched @property (nonatomic, weak) UIScrollView *scrollView; to strong in AAPullToRefresh.h error is gone.

r-plus commented 9 years ago

Probably same issue #8.

zeuspnt commented 9 years ago

@xzenon : can you tell me why ? :+1:

meilbn commented 8 years ago

You don't have to add - (void)dealloc to AAPullToRefresh.m, just add:

- (void)dealloc {
    pullToRefresh.showPullToRefresh = NO;
}

to your ViewController. it's work for me.

sbmsingh commented 8 years ago

@arielpollack Thanks for your answer man. I was stuck with the same issue for past 3 days.