ios-Loading more interfaces

Source: Internet
Author: User

Want to try pull-up load more how to start your own research trip, see two days finally made the interface.

The reason why this is so slow is that I don't know where to put the view where the pull-up appears, and I can pull it out when the scrollview pulls to the bottom. There is how to pull it out and stop here. The online download example has been studied for two days:



First of all, in the image below the orange view of the location of the use of KVO for monitoring;


An enumeration is first to indicate in which state the view is currently refreshed:

typedef enum {    refreshstateloading = 1,//Refresh status is loading    refreshstaterelease,//drop-down    before    complete release Refreshstatenomal,      //raw state}refreshstate;


The following Class View describes a refresh view


@interface Footview:uiview@property (nonatomic,strong) Uiactivityindicatorview *activity;//Activity Indicator Bar @property ( Nonatomic,strong) Uiimageview *imageview;            Arrow Picture @property (Nonatomic,strong) UILabel *infolabel;                Text Indication @property (nonatomic,assign) refreshstate refreshstate;         State of Refresh-(void) refreshstateloading;-(void) refreshstatenomal;-(void) refreshstaterelsease; @end

#import "FootView.h" @implementation footview@synthesize activity; @synthesize ImageView; @synthesize infolabel;@    Synthesize refreshstate;-(ID) initWithFrame: (cgrect) frame{self = [super Initwithframe:frame];                if (self) {self.backgroundcolor = [uicolor Orangecolor]; Activity indicator initialization activities = [[Uiactivityindicatorview Alloc]initwithactivityindicatorstyle:uiactivityindicatorviewstyleg        Ray];        Activity.frame = CGRectMake (10, 0, 50, 70);                [Self addsubview:activity];        Arrow image initialization ImageView = [[Uiimageview alloc]initwithframe:cgrectmake (10, 10, 30, 50)];        Imageview.image = [UIImage imagenamed:@ "Blackarrow.png"];                [Self addsubview:imageview];        Information Label initialization Infolabel = [[UILabel alloc]initwithframe:cgrectmake (100,0, 100, 70)];        Infolabel.text = @ "drop-down refresh ...";        Infolabel.font = [Uifont fontwithname:@ "Helvetica" size:20];        Infolabel.textalignment = Nstextalignmentcenter; Infolabel.textcOlor = [Uicolor blackcolor];                [Self Addsubview:infolabel];    Set initial state self.refreshstate = Refreshstatenomal; } return self;}    Initial state-(void) refreshstatenomal{self.refreshstate = Refreshstatenomal;    [Self.activity stopanimating];    Self.infolabel.text = @ "drop-down load more ...";    Self.imageView.layer.transform = Catransform3dmakerotation (M_PI * 2, 0, 0, 1); Self.imageView.hidden = NO;}    When data is being requested-(void) refreshstateloading{self.refreshstate = refreshstateloading;    Self.imageView.hidden = YES;    [UIView Beginanimations:nil Context:nil];    Self.infolabel.text = @ "Loading ...";    [Self.activity startanimating]; [UIView commitanimations];}    After the drop-down is complete-(void) refreshstaterelsease{self.refreshstate = refreshstaterelease;    [UIView Beginanimations:nil Context:nil];    Self.infolabel.text = @ "Load after release ...";    Self.imageView.layer.transform = catransform3dmakerotation (m_pi, 0, 0, 1);    [UIView commitanimations]; } @end

Write table below.

#import <UIKit/UIKit.h> @interface mytablevc:uitableviewcontroller<uiscrollviewdelegate> @property ( Nonatomic,strong) Nsmutablearray *dataarray;//data @end

#import "MyTableVC.h" #import "FootView.h" #define Table_cell_hight 50.0@interface MYTABLEVC () @end @implementation mytablevc{Footview *footview;}    @synthesize dataarray;-(ID) Initwithstyle: (uitableviewstyle) style{self = [super Initwithstyle:style]; if (self) {} return to self;}    -(void) viewdidload{[Super Viewdidload]; DataArray = [Nsmutablearray arraywitharray:@[@ "List 1", @ "List 2", @ "List 3", @ "List 2", @ "List 3", @ "List 2", @ "List 3", @ "List 2", @ "List 3", @ "List 2    ", @" List 3 ", @" List 2 ", @" List 3 ", @" List 2 "@" List 5 "]; [Self addpulltorefreshfooter];}  Add Footview indicator-(void) addpulltorefreshfooter{//footview Initialize Footview = [[Footview alloc]initwithframe:cgrectmake (0,    DATAARRAY.COUNT*50, 320, 251)];    [Self.tableview Addsubview:footview]; Monitor data array [self addobserver:self forkeypath:@ "DataArray" Options:nskeyvalueobservingoptionnew Context:nil];} #pragma mark-table View data source-(float) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return table_cell_hight;}-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return dataarray.count;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static    NSString *inditifiercell = @ "Cell";    UITableViewCell *cell = [TableView Dequeuereusablecellwithidentifier:inditifiercell]; if (cell = = nil) {cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:inditif    Iercell];        } cell.textLabel.text = [DataArray objectAtIndex:indexPath.row]; return cell;} -(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{Nsmutablearray *new = [[N    Smutablearray Alloc]initwitharray:dataarray];    [New addobject:@ "Zhang San"];    Self.dataarray = new;    [Footview Refreshstatenomal];    Self.tableView.contentInset = uiedgeinsetsmake (0, 0, 0, 0); } #pragma mark-kvoUsed to listen to the DataArray array to set the position of the Footview-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID) object change: (    Nsdictionary *) Change context: (void *) context{NSLog (@ "%d", dataarray.count);    Nsmutablearray *mutablearray = [Change objectforkey:@ "new"];    Footview.frame = CGRectMake (0,table_cell_hight* mutablearray.count, 320, 251); [Self.tableview Reloaddata];} #pragma mark-scroller//called when Scroller is sliding-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{if (footview.refreshst ate = = refreshstatenomal&& Scrollview.contentoffset.y > ScrollView.contentSize.height-    ScrollView.frame.size.height + +) {[Footview refreshstaterelsease]; }}//called when the swipe ends-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{if (        Footview.refreshstate = = refreshstaterelease) {[UIView beginanimations:nil context:nil];        Self.tableView.contentInset = uiedgeinsetsmake (0, 0, 70, 0);        [Footview refreshstateloading]; [UIViewCommitanimations]; }} @end


To handle some events in table:

In order to test whether the location of the Footview will change after adding the data, a data will be added when the cell is clicked;

In order to test whether the second drag-and-drop page can be completed after loading, Foottview will stop when the cell is clicked;


Download code: http://download.csdn.net/detail/u010123208/8036577

ios-Loading more interfaces

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.