In the development process of a project, the pull-down refresh and update data are often used for better experience. Of course, there are also some situations where more data is loaded by pulling up; currently, the popular egotableviewpullrefresh only implements the drop-down function, but not the pull-up function. This section describes how to integrate pull-down refresh and pull-up to load more class libraries. egotableviewpullrefresh
Class Library: https://github.com/emreberge/EGOTableViewPullRefresh
Demo effect included
Whats different on this fork:
- Easy to integrate. Use interface builder to add tableview for configuration.
- Easy configuration: Arrow portraits, background colors, and text colors can be easily changed through the properties of the pulltableview class.
- Pull up to load more data functions at the bottom of the table.
- You can use code modifications to refresh and load more animations.
The fast setup:
- Add quartzcore. Framework to your project.
- Drag egotableviewpullrefresh to your project directory.
- View the available properties of the pulltableview. h file.
- Add a pulltableview to your code to implement the pulltableviewdelegate delegate method.
- Enjoy it.
The detailed setup (walk through for creating the demo project ):
- Create a new xcode Project
- Select View Based Application Template (xcode 4.2 and later versions are single view application templates)
- Project name: egotableviewpullrefreshdemo
- Create the egotableviewpullrefreshdemoviewcontroller class under the project file (this step is not required for the single view application template)
- Add quartzcore. Framework to the Project
Add pulltableview to the project:
- Drag the files in the egotableviewpullrefresh directory to the file group supported by the project to make sure that all files in the (egotableviewpullrefresh) are copied to the target file group.
Add the pulltable view to egotableviewpullrefreshdemoviewcontroller. XIB:
- Drag a uitableview control to the view.
- Enable identity inspector to change the inheritance class of table from uitableview to pulltableview.
- Connect the datasources data source and the pulldelegate protocol to the file's owner of the pulltableview.
Configure the header file egotableviewpullrefreshdemoviewcontroller. h:
- Add # import "pulltableview. H"
- Declare the pulltableviewdelegate and uitableviewdatasource protocols
- Create an output port named pulltableview to connect to tableview on interface builder.
Configure the View Controller and footer egotableviewpullrefreshdemoviewcontroller. m
- Add the following code to the. M file:
# Pragma mark-refresh and load more methods-(void) refreshtable {/* code to actually refresh goes here. refresh the code here */self. pulltableview. pulllastrefreshdate = [nsdate date]; self. pulltableview. pulltableisrefreshing = no;}-(void) loadmoredatatotable {/* code to actually load more data goes here. load more implementation code here */self. pulltableview. pulltableisloadingmore = no;} # pragma mark-uitableviewdatasource-(NS Integer) numberofsectionsintableview :( uitableview *) tableview {return 5;}-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {return 10;}-(uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {static nsstring * cellidentifier = @ "cell"; uitableviewcell * cell = [tableview dequeuereusablewitcellhidentifier: celalert Ifier]; If (! Cell) {Cell = [[uitableviewcell alloc] initwithstyle: uitableviewcellstyledefault reuseidentifier: cellidentifier];} cell. textlabel. TEXT = [nsstring stringwithformat: @ "row % I", indexpath. row]; return cell;}-(nsstring *) tableview :( uitableview *) tableview titleforheaderinsection :( nsinteger) Section {return [nsstring stringwithformat: @ "section % I begins here! ", Section];}-(nsstring *) tableview :( uitableview *) tableview titleforfooterinsection :( nsinteger) Section {return [nsstring stringwithformat: @" section % I ends here! ", Section] ;}# Pragma mark-pulltableviewdelegate-(void) Example :( pulltableview *) pulltableview {[self defined mselector: @ selector (refreshtable) withobject: Nil afterdelay: 3.0f]; -(void) pulltableviewdidtriggerloadmore :( pulltableview *) pulltableview {[self owned mselector: @ selector (loadmoredatatotable) withobject: Nil afterdelay: 3.0f];}
- For UI configuration, add the following code in the viewdidload () method (for example, modify the refresh and pull background color arrow pictures)
self.pullTableView.pullArrowImage = [UIImage imageNamed:@"blackArrow"];self.pullTableView.pullBackgroundColor = [UIColor yellowColor];self.pullTableView.pullTextColor = [UIColor blackColor];
if(!self.pullTableView.pullTableIsRefreshing) { self.pullTableView.pullTableIsRefreshing = YES; [self performSelector:@selector(refreshTable) withObject:nil afterDelay:3];}
Original blog welcome to repost share, please indicate the source of http://blog.csdn.net/duxinfeng2010