IOS learning path-pull-down refresh and pull-up loading more, ios path

Source: Internet
Author: User

IOS learning path-pull-down refresh and pull-up loading more, ios path
IOS learning path-pull-down refresh and pull-up loading

In this article, I will share with you the pull-down refresh and pull-up methods to load more functions commonly used in the app.

Content 1. Implementation methods and advantages and disadvantages of each method

After using Meituan, comments should have noticed that when you slide the Form up, more shops will be loaded into your form, and when you drop the form top, the content of the form is refreshed and the latest information is obtained from the network. More functions can be loaded through pull-down refresh and pull-up, so that the app can obtain information that more users want and obtain the latest information. So how can this function be implemented? Please continue with the author.

Currently, the main implementation methods are as follows:

1. UIRefreshControl: a refresh method inherent in iOS's UIkit. It is the most basic and original method.

2. Custom: You can create personalized refresh tools, but they are complicated and prone to problems. We do not recommend new users and those who need to use them on time.

3. AH3DPullRefresh

The specific settings are as follows:

Set the Flags of UIScrollView + AH3DPullRefresh. m to-fno-objc-arc in the Compile Sources of Build Phases to run normally.

4. MJRefresh: Convenient and convenient. It is a refresh loading tool that I personally think is the most convenient and compatible.

5. other open-source libraries: There are many open-source libraries on the Internet, including the 3 and 4 recommended above. There are also many different types of libraries on the Internet, if you are interested, you can go to CocoaChina or other websites that provide open-source code to search for a suitable one.

2. Specific instance

Next, let's take a look at MJRefresh and the specific implementation process of a nice pull-down refresh named YALSunnyRefreshControll downloaded from CocoaChina.

First, add the drop-down refresh and add the YALSunnyRefreshControll folder to the project.

Then add the header file # import "YALSunnyRefreshControl. h" in the drop-down and refresh. h file, and add a YALSunnyRefreshControl object for the class @ property.

:

Then initialize the YALSunnyRefreshControl and associate it with the UITableView or UICollectionView to implement the refresh function. The specific code is as follows:

Finally, we will introduce the images required to refresh the animation. These images will be downloaded together with the code. You can use them or change them to your own.

The final result is shown as follows:

When the drop-down table is displayed, the sun rises and the House animations appear on the top of the table. Is it nice? And the content is refreshed. This tool is really easy to use and looks good.

Next, I use MJRefresh to load more data from the network and display it to the form.

The first step is to add the MJRefresh package to the project and introduce it to the. m file that needs to be used.

Then, create a global variable for MJRefresh in the file, and then initialize it and associate it with tableView. The Code is as follows:

My code [self startDownload] is used to load 10 pieces of data from the _ offset Entry on the Internet to the local device, _ offset + = 10 and then call [self startDownload] to load more than 10 pieces of data to my application. After the download is complete, remember to call the reloadData method of tableView, to display the newly loaded data to the form.

After loading, you also need to call a stop method to stop loading. Otherwise, the next load cannot be performed. The following method is called at the end of the method for loading data to your tableView datasource.

The above two methods are called for loading and refreshing methods respectively. It is best to call the reloadData method of tableView before calling;

In this way, the function of loading and refreshing is completed. The loading is as follows:

I said that I am not familiar with Apple, but I will only use screenshots...

3. Conclusion

In short, the above is my personal summary of how the pull-down refresh and pull-up loading functions are implemented. If you think I have something wrong or not, please give me more advice, you can contact me through a blog or leave a comment under the article. Thank you ~.

Related Article

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.