In iOS development, it is often necessary to add the UITableView drop-down refresh feature, which can be easily implemented with Uirefreshcontrol.
Uirefreshcontrol
Below is the Uirefreshcontrol's header file.
ImportFoundationImportUIKit////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 had Pulled-to-refresh, the Uirefreshcontrol fires its Uicontroleventvaluechanged event. */Init ()varRefreshing:bool {Get}vartintcolor:uicolor!varAttributedtitle:nsattributedstring?//May is used to indicate to the Refreshcontrol, the external event has initiated the Refresh action@availability (IOS, introduced=6.0)funcBeginrefreshing ()//must be explicitly called when the refreshing have completed@availability (IOS, introduced=6.0)funcEndrefreshing ()}
It can be seen that the invocation method provided is simple, init () is necessary to create the control, followed by the two methods of Beginrefreshing () and endrefreshing () to control the refresh.
Working with instances
Take UITableView refresh as an example, the use of Uirefreshcontrol is divided into 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 the 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:"Drop-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() }
Uirefreshcontrol---Controls for refreshing uitableview, etc. in iOS