UIRefreshControl, code4app

Source: Internet
Author: User

UIRefreshControl, code4app

During IOS development, you often need to add the pull-down refresh function of UITableView, which can be easily implemented by using UIRefreshControl.

UIRefreshControl

Below is the header file of UIRefreshControl.

import Foundationimport UIKit////  UIRefreshControl.h//  UIKit////  Copyright 2012-2014 Apple Inc. All rights reserved.//@availability(iOS, introduced=6.0)class UIRefreshControl : UIControl {    /* The designated initializer     * This initializes a UIRefreshControl with a default height and width.     * Once assigned to a UITableViewController, the frame of the control is managed automatically.     * When a user has pulled-to-refresh, the UIRefreshControl fires its UIControlEventValueChanged event.     */    init()    var refreshing: Bool { get }    var tintColor: UIColor!    var attributedTitle: NSAttributedString?    // May be used to indicate to the refreshControl that an external event has initiated the refresh action    @availability(iOS, introduced=6.0)    func beginRefreshing()    // Must be explicitly called when the refreshing has completed    @availability(iOS, introduced=6.0)    func endRefreshing()}

It can be seen that the call method provided by it is very simple. init () is required to create the control, followed by the inrefreshing () and endRefreshing () methods to control the refresh.

Use instance

Taking refresh of UITableView as an example, the use of UIRefreshControl involves the following steps:
1. initialize a UIRefreshControl object.
2. Add the method called when refreshing. Here is the refreshDataSource () method.
3. Add the UIRefreshControl object to tableView.
Then, drop down the device screen to see the effect.

Var refreshCtl = UIRefreshControl () var httpCtl: HttpController = HttpController () // outlets @ IBOutlet weak var tableView: UITableView! Override func viewDidLoad () {super. viewDidLoad () // Do any additional setup after loading the view, typically from a nib. httpCtl. delegate = self refreshCtl. attributedTitle = NSAttributedString (string: "pull-down refresh") refreshCtl. addTarget (self, action: "refreshDataSource", forControlEvents: UIControlEvents. valueChanged) tableView. addSubview (refreshCtl) refreshDataSource ()} func refreshDataSource () {refreshCtl. beginRefreshing () httpCtl. getDataViaNSURLConnection ("http: // 0.0.0.0/dataapi") refreshCtl. endRefreshing ()}

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.