for (EGORefreshTableHeaderView *view in [cardsTableView subviews]) {
[view removeFromSuperview];
}
The code above removes all subviews from cardsTableView
, not just the subviews that are of EGORefreshTableHeaderView
type.
Another way to write that would be:
for (id objInSubviews in [cardsTableView subviews]) {
EGORefreshTableHeaderView *view = (EGORefreshTableHeaderView *)objInSubviews;
[view removeFromSuperview];
}
You're just telling the for
loop to treat the objects as EGORefreshTableHeaderView
instances, not to loop only through the objects that are in fact EGORefreshTableHeaderView
.
Instead, you want something like this:
for (id objInSubviews in [cardsTableView subviews]) {
if([objInSubviews isKindOfClass:[EGORefreshTableHeaderView class]]){
EGORefreshTableHeaderView *view = (EGORefreshTableHeaderView *)objInSubviews;
[view removeFromSuperview];
}
}
Or even better, if you have a variable that hods the pull to refresh, you can skip the loop all together. My guess is that _refreshHeaderView
is that variable in your case, if so, you can safely remove the loop.
Note that you have another bug here:
_refreshHeaderView = nil;
[_refreshHeaderView removeFromSuperview];
This is just like calling [nil removeFromSuperview];
- which does nothing. You need to reverse the order:
[_refreshHeaderView removeFromSuperview];
_refreshHeaderView = nil;