Coder Social home page Coder Social logo

mdabbagh88 / refreshablescrollview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adib/refreshablescrollview

0.0 0.0 0.0 369 KB

NSScrollView subclass that supports pull-to-refresh both in top and bottom edges.

License: BSD 3-Clause "New" or "Revised" License

Ruby 16.84% Objective-C 83.16%

refreshablescrollview's Introduction

RefreshableScrollView

An NSScrollView subclass that supports pull-to-refresh both in the top and bottom edges. The intended usage is for hosting a timeline-like view that shows a list of messages in reverse-chronological order.

<iframe width="560" height="315" src="http://www.youtube.com/embed/pCsKe3n8sEw?list=UUjGxuNIAufU923dtBuyC82A&hl=en_US" frameborder="0" allowfullscreen></iframe>

Getting Started

Attach RefreshableScrollView.xcodeproj into your OS X project and add libRefreshableScrollView.a as a dependency in your project. Also include the public header file BSRefreshableScrollView.h into your project's user header search paths.

Play around with the included example application to see the class in action and how it is being used. The video demo above shows a recording of this sample application.

How to use

Use BSRefreshableScrollView as a replacement of NSScrollView. If you use Xcode's interface builder to add instances of NSTableView or NSOutlineView (among others), by default it will enclose those objects inside an NSScrollView. Highlight this NSScrollView container, go to the object' identity inspector and type in BSRefreshableScrollView as the scroll view's class name.

Then you'll need to write a delegate that conforms to BSRefreshableScrollViewDelegate protocol. Most likely this will be the xib's file owner โ€“ a view controller or a window controller. Attach this delegate class to the refreshableDelegate outlet of the scroll view.

In awakeFromNib method of the delegate, setup which sides that supports pull-to-refresh. This is important โ€“ without enabling these flags, BSRefreshableScrollView will behave just like a plain old NSScrollView. If you don't use xib files then you'll need to find an appropriate place to set these flags. Note that you can clear any of these flags to disable refresh for their respective sides even when the view is already visible.

-(void)awakeFromNib
{
    [super awakeFromNib];
    self.refreshableScrollView.refreshableSides = BSRefreshableScrollViewSideTop | BSRefreshableScrollViewSideBottom;
}

Start the refresh process in your delegate by implementing method scrollView: startRefreshSide: and return YES if the process was successfully started. The scroll view will then display an indeterminate progress indicator at the appropriate edge. If for some reason you couldn't initiate refresh for that side, simply return NO and the scroll view will behave as if nothing happened.

#pragma mark BSRefreshableScrollViewDelegate

-(BOOL) scrollView:(BSRefreshableScrollView*) aScrollView startRefreshSide:(BSRefreshableScrollViewSide) refreshableSide
{
    if (refreshableSide == BSRefreshableScrollViewSideTop) {
	    // initiate refresh process for the top edge of the scroll view
	    // ...
	    return YES; // tell the scroll view to display the progress indicator
    } else if (refreshableSide == BSRefreshableScrollViewSideBottom) {
	    // initiate refresh process for the bottom edge of the scroll view
	    // ...
	    return YES; 
    }
    return NO;
}

When the refresh process have completed (i.e. the network service have returned a result or timed out), call stopRefreshingSide: and give it the appropriate edge to stop. If there was no refresh currently in progress at that side this calling this method will have no effect. For example:

- (IBAction)stopRefreshTop:(id)sender
{
    [self.refreshableScrollView stopRefreshingSide:BSRefreshableScrollViewSideTop];
}

License

This project is licensed under the BSD license. Please let me know ([email protected]) if you use it for something interesting.

Sasmito Adibowo http://cutecoder.org

refreshablescrollview's People

Contributors

adib avatar

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.