IOS development-iOS 7 pull-down refresh, loading on quick integration

Source: Internet
Author: User

Before ios7, the open source EGO library has been used. However, during use, it is found that the encapsulation is too complex and the coupling is strong, which is not conducive to integration into your own projects.

In addition, some original pull-down refreshes after ios7, and the loading control is not so outstanding. In addition to possible errors, it does not conform to the flat style.

Later, I found a Daniel uploaded an open source code on code4App. Just a few lines of code can be used to add a pull-down or pull-up refresh function to UITableView or CollectionView. You can customize text descriptions for up/down refresh.

Download the package and try it out. Mark.

 

The following is a record of your integration process. Of course, the demo provided by the author has already been detailed. This is just a record of your own implementation process.

 

1. Import the entire MJRefresh folder to the required project.

2. The MJRefresh. bundle ---> arrow@2x.png image in the folder can be replaced by itself, which will be displayed during the refresh process.

3. You can customize the displayed text content and color in the MJRefreshConst. h and MJRefreshConst. m files.

4. As long as your view can be rolled, You can integrate this control, such as UIScrollView, UITableView, and UICollectionView.

5. Add the following code as needed.

5.1 import header files

#import MJRefresh.h

 

5.2 compliance

 

@interface ViewController ()
 

5.3 add controls for your view

 

 

MJRefreshFooterView *footer = [MJRefreshFooterView footer];    footer.scrollView = myTableView;    footer.delegate = self;        MJRefreshHeaderView *header = [MJRefreshHeaderView header];    header.scrollView = myTableView;    header.delegate = self;

5.4 proxy method implementation

 

 

# Pragma mark-proxy method for refreshing controls # pragma mark begins to enter the refresh status-(void) refreshViewBeginRefreshing :( MJRefreshBaseView *) refreshView {NSLog (---- starts to enter the refreshView status. class); // refresh the table UI after 2.2 seconds [self defined mselector: @ selector (doneWithView :) withObject: refreshView afterDelay: 2.0];} # refresh pragma mark-(void) refreshViewEndRefreshing :( MJRefreshBaseView *) refreshView {NSLog (@ ---- refresh finished, refreshView. class) ;}# pragma mark listens for changes to the refresh status-(void) refreshView :( MJRefreshBaseView *) refreshView stateChange :( MJRefreshState) state {switch (state) {case MJRefreshStateNormal: NSLog (@ % @ ---- switch to: normal status, refreshView. class); break; case MJRefreshStatePulling: NSLog (@ % @ ---- switch to: refresh status after releasing, refreshView. class); break; case MJRefreshStateRefreshing: NSLog (@%@---- switch to: Refreshing status, refreshView. class); break; default: break ;}# pragma mark refreshes the table and ends refreshing status-(void) doneWithView :( MJRefreshBaseView *) refreshView {// refresh the table [myTableView reloadData]; // (preferably called after refreshing the table) Call endRefreshing to end the refresh status [refreshView endRefreshing];}


 

6. You can call beginRefreshing to automatically enter the pull-down refresh status.

7. You can call endRefreshing to end the refresh status.

8. To prevent internal leakage, it is best to release the occupied memory in the Controller's dealloc.
-(Void) dealloc
{
[_ Header free];
[_ Footer free];
}

 

 

:

  • Code update function of 2014.02.08:

    1. Fixed the BUG of "pulling and loading more controls without data;

    2. Fixed the memory leakage of the Controller in the example program.

    Code update function of 2014.01.03:

    1. Perfect fit for iOS6iOS7 and iPhone iPad horizontal and vertical screen

    2. added a callback mechanism for refreshing control status changes.

    3. Solved the inexplicable BUG of pulling and loading more files that have remained for a long time, and enhanced the user experience.

    4. The redundant audio playback function is deleted.

    5. added the memory release function to solve the memory leakage BUG.

    2013.01.03 code update function:

    1. compatible with iPhone horizontal and vertical screens and iPad horizontal and vertical screens;

    2. You no longer need to call the free Method to release the resources of the refresh control;

    3. Demonstrate the block callback of the refresh control;

    4. demonstrate the use of the refresh control on UICollectionView.

    The author said: open-source pull-up and refresh controls on the Internet are generally encapsulated too complicated and highly coupled. Therefore, I spent some time writing a set of uncoupled and pluggable refresh controls, which are non-invasive to other code in the project and easy to use. The three lines of code can be integrated with the refresh control.

    Editor note: thanks to the developer @ M for publishing a J code on Code4App.com.>

  • Code update function of 2014.02.08:

    1. Fixed the BUG of "pulling and loading more controls without data;

    2. Fixed the memory leakage of the Controller in the example program.

    Code update function of 2014.01.03:

    1. Perfect fit for iOS6iOS7 and iPhone iPad horizontal and vertical screen

    2. added a callback mechanism for refreshing control status changes.

    3. Solved the inexplicable BUG of pulling and loading more files that have remained for a long time, and enhanced the user experience.

    4. The redundant audio playback function is deleted.

    5. added the memory release function to solve the memory leakage BUG.

    2013.01.03 code update function:

    1. compatible with iPhone horizontal and vertical screens and iPad horizontal and vertical screens;

    2. You no longer need to call the free Method to release the resources of the refresh control;

    3. Demonstrate the block callback of the refresh control;

    4. demonstrate the use of the refresh control on UICollectionView.

    The author said: open-source pull-up and refresh controls on the Internet are generally encapsulated too complicated and highly coupled. Therefore, I spent some time writing a set of uncoupled and pluggable refresh controls, which are non-invasive to other code in the project and easy to use. The three lines of code can be integrated with the refresh control.

    Editor note: thanks to the developer @ M for publishing a J code on Code4App.com.>

  • Code update function of 2014.02.08:

    1. Fixed the BUG of "pulling and loading more controls without data;

    2. Fixed the memory leakage of the Controller in the example program.

    Code update function of 2014.01.03:

    1. Perfect fit for iOS6iOS7 and iPhone iPad horizontal and vertical screen

    2. added a callback mechanism for refreshing control status changes.

    3. Solved the inexplicable BUG of pulling and loading more files that have remained for a long time, and enhanced the user experience.

    4. The redundant audio playback function is deleted.

    5. added the memory release function to solve the memory leakage BUG.

    2013.01.03 code update function:

    1. compatible with iPhone horizontal and vertical screens and iPad horizontal and vertical screens;

    2. You no longer need to call the free Method to release the resources of the refresh control;

    3. Demonstrate the block callback of the refresh control;

    4. demonstrate the use of the refresh control on UICollectionView.

    The author said: open-source pull-up and refresh controls on the Internet are generally encapsulated too complicated and highly coupled. Therefore, I spent some time writing a set of uncoupled and pluggable refresh controls, which are non-invasive to other code in the project and easy to use. The three lines of code can be integrated with the refresh control.

    Editor note: thanks to the developer @ M for publishing a J code on Code4App.com.>

  • Code update function of 2014.02.08:

    1. Fixed the BUG of "pulling and loading more controls without data;

    2. Fixed the memory leakage of the Controller in the example program.

    Code update function of 2014.01.03:

    1. Perfect fit for iOS6iOS7 and iPhone iPad horizontal and vertical screen

    2. added a callback mechanism for refreshing control status changes.

    3. Solved the inexplicable BUG of pulling and loading more files that have remained for a long time, and enhanced the user experience.

    4. The redundant audio playback function is deleted.

    5. added the memory release function to solve the memory leakage BUG.

    2013.01.03 code update function:

    1. compatible with iPhone horizontal and vertical screens and iPad horizontal and vertical screens;

    2. You no longer need to call the free Method to release the resources of the refresh control;

    3. Demonstrate the block callback of the refresh control;

    4. demonstrate the use of the refresh control on UICollectionView.

    The author said: open-source pull-up and refresh controls on the Internet are generally encapsulated too complicated and highly coupled. Therefore, I spent some time writing a set of uncoupled and pluggable refresh controls, which are non-invasive to other code in the project and easy to use. The three lines of code can be integrated with the refresh control.

    Editor note: thanks to the developer @ M for publishing a J code on Code4App.com.>

     

    On the way to learning, I will share with you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.