Coder Social home page Coder Social logo

samvermette / svpulltorefresh Goto Github PK

View Code? Open in Web Editor NEW
4.8K 4.8K 1.1K 960 KB

Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.

Home Page: http://samvermette.com/314

License: MIT License

Objective-C 97.95% Ruby 2.05%

svpulltorefresh's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svpulltorefresh's Issues

Issues with scrollView that have predefined contentOffset.y's

I was having some problems using the new version with my UIScrollView that has a non-zero contentOffset.y and contentInset.top in some situations. For instance, if you scroll up on this view, it also pushes a menu that sits at the very top of the view up and out of the window (while reducing the inset.top and increase the offset.y).

I solved this problem by creating a new property:
@property (nonatomic, readwrite) CGFloat originalYOffset;

And setting it inside of - (void)addPullToRefreshWithActionHandler::
view.originalYOffset = self.contentOffset.y;

And now my - (void)startAnimating and - (void)stopAnimating functions look like:

- (void)startAnimating{
    if(self.scrollView.contentOffset.y >= self.originalYOffset) {
        [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, self.originalYOffset - self.frame.size.height) animated:YES];
        self.wasTriggeredByUser = NO;
    }
    else
        self.wasTriggeredByUser = YES;

    self.state = SVPullToRefreshStateLoading;
}

- (void)stopAnimating {
    if (self.state != SVPullToRefreshStateStopped)
    {
        self.state = SVPullToRefreshStateStopped;

        if(!self.wasTriggeredByUser)
            [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, self.originalYOffset) animated:YES];
    }
}

Two small things to note:

  1. The check at the top of - (void)startAnimating only checked if the current offset.y is equal to 0, but should evaluate to true as long as it's not the user pulling it past the "natural" zero-th position of the scrollView. An alternative to what I did is:
    if(self.scrollView.contentOffset.y >= -self.originalTopInset)
  2. I added a check inside of - (void)stopAnimating to see if the the animation needs to be stopped. This avoids the problem where the content offset start popping back to the top if - (void)stopAnimating gets called conservatively by the scrollView right before it gets dismissed

cause leaks test on iPad 5.1 simulator

Hi All,
i test the SVPullToRefresh demo on iPad 5.1 simulator and use instruments to profile. when i drag up and down the table view, then found the leaks.

Hiding just UIActivityIndicator

Is it possible to hide just a UIActivityIndicator? This might be useful if a custom UIActivityIndicator were to implement outside a UITableView header.

BridgeSupport is not parsing files properly

Hi. So, I'm pretty new to iOS development and I'm actually using RubyMotion. I really like this implementation of "pull to refresh" and I'd like to use it in my RubyMotion project via cocoapods (and motion-cocoapods). However, the .bridgesupport file is missing the UIScrollView extensions. I know that this is probably an issue with gen_bridge_metadata, but I thought I'd see if you are familiar with MacRuby/RubyMotion and what it does to get Obj-C projects working.

Here's the file:

<?xml version='1.0'?>
<signatures version='1.0'>
<class name='SVPullToRefresh'>
<method selector='activityIndicatorViewStyle'>
<retval declared_type='int' type='i'/>
</method>
<method selector='arrowColor'>
<retval declared_type='int*' type='^i'/>
</method>
<method selector='setActivityIndicatorViewStyle:'>
<arg name='activityIndicatorViewStyle' declared_type='int' type='i' index='0'/>
<retval declared_type='void' type='v'/>
</method>
<method selector='setArrowColor:'>
<arg name='arrowColor' declared_type='int*' type='^i' index='0'/>
<retval declared_type='void' type='v'/>
</method>
<method selector='setTextColor:'>
<arg name='textColor' declared_type='int*' type='^i' index='0'/>
<retval declared_type='void' type='v'/>
</method>
<method selector='stopAnimating'>
<retval declared_type='void' type='v'/>
</method>
<method selector='textColor'>
<retval declared_type='int*' type='^i'/>
</method>
</class>
</signatures>

Any assistance would be much appreciated.

PullToRefresh disappears if the UITableViews owning it is not wrapped up in a UIView

I have this case where i do not use any UIViewControllers subclasses but instead straight
UITableViewController subclasses sitting in a UINavigationController

so, the UITableView owning PullToRefresh is not sitting in a UIView.

now, when i transition from one controller to another using pushViewController, the pulltorefresh functionality vanishes.
I figured it was because of this :

@implementation UIScrollView (SVPullToRefresh)

  - (void)willMoveToSuperview:(UIView *)newSuperview
  { 
    if(!newSuperview)
    {
      [self.pullToRefreshView removeFromSuperview];
      self.pullToRefreshView = nil;

      [self.infiniteScrollingView removeFromSuperview];
      self.infiniteScrollingView = nil;
    }
  }

I'm no view hierarchy expert so, guess i'll stick with creating my UITableViews inside UIViewControllers as it works fine that way :D

InfiniteScrollingWithActionHandler triggered twice without waiting until the first one finishes

__unsafe_unretained BrowseLookViewController *vc=self; 
[self.lookFeedView.mainTableView addInfiniteScrollingWithActionHandler:^{
    [vc loadLooksToFeedView];
}];

With the above code, I found some strange behavior of InfiniteScrolling.
While I am scrolling down to the bottom and still dragging more and more to the bottom, I found that loadLooksToFeedView was called twice in a row.
How can I ensure that this will be called only once and finishes before the next call begins.

Does InfiniteScrolling already prevent this from occurring or have I done anything wrong?
Does it check progressIndicator status whether it is still animating before executing the action handler?

Empty table view loses cell separators with infinite scrolling

Before adding addInfiniteScrollingWithActionHandler: an empty default table view (numberOfRows returning 0) will have blank cells marked with light grey separators. After adding the above method, an empty table view will appear more like a blank scroll view before cells are populated and added. Once cells are added, everything is great! Any suggestions?

DataSource = 0

Hello,
I''m using GMGridView to display my data and added the PTR , it works good but if there is no internet connection and the number of cells = 0 it doesn't appear and no scroll is done , how can I get this fixed ?

Please add a version tag.

This implementation is awesome! Could you add a version tag so that I can commit it into CocoaPod Specs.

Background color?

Is it possible to change the backgroundcolor for the pulltorefresh view?

Consider hiding date label if showsPullToRefresh is NO

I wanted to hide SVPullToRefresh when the user is editing a table. I have mine set up to show a refresh date. The refresh date still is displayed when I use:

    tableView.showsPullToRefresh = NO

I'm not sure if that was the original intention but if not, I think it would be good to hide it.

For the time being, my work around is:

    tableView.showsPullToRefresh = !editing;
    tableView.pullToRefreshView.dateLabel.hidden = editing;

present view controller with completion block issues

I'm trying to present a modal view controller after the pull to refresh. I can present it fine but it doesn't animate. Is there something I should be aware of when presenting a view controller from within a block?

Minor bug with removing non-existing observers

Hi Sam, thanks for your awesome library. I found a bug in your new version, but it has a simple fix.

In - (void)setShowsPullToRefresh:, it keys entirely off of the passed in BOOL for whether or not to add/remove observers. This could be a problem if I accidentally call self.scrollview.showsPullToRefresh = NO twice in a row (or if I call it before adding an action handler).

There probably is a cleaner way to do this, but I modified your code in two places:

  1. I set self.pullToRefreshView.hidden = YES right after its created; and,
  2. I modified your code to first check if (self.pullToRefreshView && self.pullToRefreshView.hidden != !showsPullToRefresh) before adding/removing observers (it's written in this funky way just to make it more readable as it mimics your code a line later... but this is probably only necessary because I don't know your code as well :P)

I did the same thing for infinite scrolling.

0.3 => 0.4

Could you please tag the current commit with a 0.4 version ? So we can update the Podspec.

Infinite view did not works well with UICollectionView on iOS6 (or PSTCollectionView on iOS < 6)

Hi,

Thanks for awesome library ๐Ÿ‘ .

The pull to refresh view work well for UICollectionView, since UICollectionView is subclass of UIScrollView. It seems the infinite view doesn't show on UICollectionView though.

I believe you can reproduce by checkout the sample about UICollectionView or PSTCollectionView ( https://github.com/steipete/PSTCollectionView) then add SVPullToRefresh. I can see the infinite scroll handler is triggered, however the view is not there.

Support for prepending items on pull to refresh

I'm using SVPullToRefresh in my calendar application to load previous events when scrolling upwards and infinite scroll to load next events.

With previous version I managed to make it work so that after reloading the TableView with new data prepended I scrolled to the previously first item and called stopAnimating and it worked like a charm, the last of the now prepended items replaced the loader and I could continue scrolling upwards.

With current version if I do the same it always scrolls to the first item in the table. Changing the execution order to stopAnimating before TableView's reloadData and scroll there's short flickering as the table scrolls to empty first item, reloads and then back to the previously first item.

Any ideas how to make it smooth again? Diff for the change between old and new SVPullToRefresh at anqqa/klubitus-ios@680f5d0

KVO Error on Table View dealloc

I'm getting the following error message when a table view I have attached pullToRefresh to is deallocated:

An instance 0x882e800 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 0x8156ef0> (
<NSKeyValueObservance 0x8156e30: Observer: 0x8154b70, Key path: contentOffset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x82419b0>
<NSKeyValueObservance 0x8156eb0: Observer: 0x8154b70, Key path: frame, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x8247fc0>
)

Am I doing something wrong? Is there a conventional way to break the KV observance I'm not aware of?

The only code I'm running related to pull-to-refresh is:

[self.tableView addPullToRefreshWithActionHandler:^{
    [tempManager updateQueue];
}];

and

[self.tableView.pullToRefreshView stopAnimating];

Thanks.

Infinite Scrolling is not so friendly.

Every time the table to it's end, it will load data automatically, I think it's not should be. When table view to end, footer shows with label "Pull to load more...", and when people drag up then the indicator with label "loading..." shows, and load data. I think it's more friendly, I have work on for this for several hours and over my head. So I come here for your help, could you add the function? Thanks.

Background color issue when view is created without width

Hi,

I'm integrating SVPullToRefresh with my project and noticed that it's not working correctly with views created directly from code and not using Interface Builder.

SVPullToRefresh needs to use autoresizing masks to work correctly.
It was a quick fix by adding one line to initWithScrollView:

- (id)initWithScrollView:(UIScrollView *)scrollView {
    self = [super initWithFrame:CGRectZero];
    self.scrollView = scrollView;

    // default styling values
    self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    self.textColor = [UIColor darkGrayColor];

    self.originalScrollViewContentInset = self.scrollView.contentInset;

    self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    return self;
}

iOS 4.3 compatibility

If i use this library in iOS 4.3, Xcode says : "The current deployment target does not support automated __weak references". Can i replace @Property (nonatomic, weak) UIScrollView *scrollView to
@Property (nonatomic, unsafe_unretained) UIScrollView *scrollView ? Project don't use ARC.

Background color issue and arrow color not being set

Hi,

I wad fiddling with this component and I think I found something that you might wanna fix. Both are described in the screenshot below:

issue

1 - The background color and view does not have a flexible height, so when I apply a background color to it, I get this weird result
2 - The arrow color is not being set correctly

Here's a snippet of the code I'm using

// Pull to refresh setup
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];

self.tableView.pullToRefreshView.dateFormatter = dateFormatter;
[self.tableView.pullToRefreshView setTextColor:[UIColor whiteColor]];
[self.tableView.pullToRefreshView setArrowColor:[UIColor redColor]];
[self.tableView.pullToRefreshView setBackgroundColor:[UIColor blackColor]];
__block KPPackagesViewController *weakSelf = self;
[self.tableView addPullToRefreshWithActionHandler:^{
    [weakSelf reloadTableViewDataSource];
}];
// END: Pull to refresh setup

I tried cleaning the project, removing the app from simulator etc just to make sure but the problem persists.

Thanks

dealloc of SVPullToRefresh is not called

If one converts the associated sample into a navigation based application with pushing of multiple SVViewController.xib by first adding a button in xib and then pushing the same view controller with tapping of that button. When we go back by tapping on the back button then the memory is not released back. This is probably due to the dealloc of both the view controller as well as SVPullToRefresh is not being called.
Also the latest version of SVPullToRefresh also gets crashed when the pull to refresh is in action and one goes back to previous view controller [pop action]

InnifiteScrollingView

How to disable accelerate of scrollView when innifite?. It make my eye disorder. :)

And a bug: Activity indicator of scrollview not show.

Thanks for best project.

ScrollView Horizontal Content Offset Overwritten

When SVPullToRefresh calls - (void)startAnimating the horizontal content offset of the underlying scroll view is reset to 0.

[self.scrollView setContentOffset:CGPointMake(0, -self.frame.size.height) animated:NO];

This caused my scrollView to lose its horizontal content offset.

I was able to resolve by using the scrollView's original contentOffset.x with the following adjustment

[self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, -self.frame.size.height) animated:NO];

Add way to disable

Would it be possible to had a way to enable or disable the pull to refresh?

Issues when multiple tables are on screen

I've been seeing a performance issue where we have multiple table/scroll views on screen (iPad), all of which have a pull to refresh handler attached. It causes incredible slowdown on the draw thread, but I can't figure out why it's happening. Removing the class causes the performance issues to be resolved.

Using pull to refresh on horizontal tables.

I have had success using the SVPullToRefresh on UITables which are oriented vertically - the traditional way.
I have a table that is rotated to display horizontally. I tried using class for this horizontal table. Unfortunately it crashes at:

  • (void)setScrollViewContentInset:(UIEdgeInsets)contentInset {
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState animations:^{
    self.scrollView.contentInset = contentInset;
    } completion:^(BOOL finished) {
    ====>>> if(self.state == SVPullToRefreshStateHidden && contentInset.top == self.originalScrollViewContentInset.top)
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
    arrow.alpha = 0;
    } completion:NULL];
    }];
    }

Any clues what I need to do to make this class work for horizontal tables as well?

add SVPullToRefresh to webview

how can i add your amazing pulltorefresh to a webview? i use it with tableview and it works perfectly....but with webview no....teorically it is a uiview subclass... so?

Thanks for your work

update example with custom title and subtitle

Hi, thanks so much for this library.
would it be possible to update your example to show how to add custom title and subtitle?

I'd like to add a subtitle that adds "Last refresh date:some-date".

I've tried using the setter methods setTitle, setSubtitle but am not having any luck. Oddly enough, they don't seem to be called, even though I'm calling them unless I call them from the action handler. I've tried to call them from my vc directly as well in my action block but no luck.

Note: this modification to the library works allows the method to work for setting the subtitle from my vc:

  • (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state {
    self.showsDateLabel = YES; //modified line (set to NO in init)
    ....
    }

Also - this still does not show the subtitle until it is run once. This produces the last refresh subtitle I would like, however, it does not show on first run. I'd like to also be able to set last refresh before they actually trigger a refresh. Is this possible?

any help would be appreciated.
thanks!

Getting crash when I simulate a memory warning

I have a simple nav baed app. I push the tableviewcontroller that contains pulltorefresh, works as advertised. I pop back to previous view and trigger a memory warning in the simulator. Generally it crashes first try, sometimes second. Commenting out the svpulltorefresh fixes the crash when I trigger the memory warning in the same way. I think a message is being sent to a deallocated obj.

Expose titleLabel and subtitleLabel

Hey Sam, I am wondering if it is a good idea that we expose the titleLabel and subtileLabel properties in SVPullToRefreshView.

I'd like to do some custom configurations on such kinds of labels, but I don't want to modify code in your library. You know, I may use pull-to-refresh in many situations and they look little different.

willMoveToSuperview implementation prevents using UIScrollView as a root view in a navigation controller

When the navigation controller pushes on a new controller, the previous view is removed from the hierarchy (but not released) and so willMoveToSuperview gets called. This means that when the user returns to the view, the pullToRefresh instance is re-created and doesn't function as expected.

My understanding is that an associated object marked "retain" will be released along with the owning object. If this is the case (and I could be mistaken), this pre-emptive removal of the views may be unnecessary.

I'm running this in iOS6 simulator in Xcode 4.5 GM

Setting textColor property creates label placement problem

if I am not using any lastupdatedate and setting the textColor property, there is a misplacement of the titleLabel. Commenting out dateLabel as below fixed the problem but there should be a better solution.

  • (void)setTextColor:(UIColor *)newTextColor {
    self.titleLabel.textColor = newTextColor;
    //self.dateLabel.textColor = newTextColor;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.