Ios-pull up to load more interfaces

Source: Internet
Author: User

Ios-pull up to load more interfaces

I want to try to pull up and load more ways to start my own research journey. After two days, I finally made a page.

The reason for this slowness is that I don't know where to put the view shown on the top, so I can be pulled out when the scrollView is pulled to the bottom. There is also how to pull it out and stop it here. After downloading the example online, I studied it for two days:

 

First, kvo is used for listening when processing the orange view position in the image below;

 

First, an enumeration is used to indicate the status in which the view is refreshed:

 

Typedef enum {RefreshStateLoading = 1, // The refresh status is loading refreshstaterelal, // RefreshStateNomal before the release is completed in the drop-down list, // original status} RefreshState;


 

The following Class view describes how to refresh a view.

 

 

@ Interface FootView: UIView @ property (nonatomic, strong) UIActivityIndicatorView * activity; // activity indicator bar @ property (nonatomic, strong) UIImageView * imageView; // arrow image @ property (nonatomic, strong) UILabel * infolabel; // Text indicator @ property (nonatomic, assign) RefreshState refreshState; // refresh state-(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 activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray]; 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, 70)]; infolabel. text = @ pull-down refresh ...; infolabel. font = [UIFont fontWithName: @ Helvetica size: 20]; infolabel. textAlignment = NSTextAlignmentCenter; infolabel. textColor = [UIColor blackColor]; [self addSubview: infolabel]; // set the initial state self. refreshState = RefreshStateNomal;} return self;} // initial state-(void) refreshStateNomal {self. refreshState = RefreshStateNomal; [self. activity stopAnimating]; self. infolabel. text = @ pull down to load more ...; self. imageView. layer. transform = CATransform3DMakeRotation (M_PI * 2, 0, 0, 1); self. imageView. hidden = NO;} // when requesting data-(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
 
  
@ Interface MyTableVC: UITableViewController
  
   
@ 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 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 initialization footView = [[FootView alloc] initWithFrame: CGRectMake (0, dataArray. count * 50,320,251)]; [self. tableView addSubview: footView]; // monitoring 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) Resume :( UITableView *) tableView {return 1;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return dataArray. count;}-(UITableViewCell *) tableView :( UITableView *) tableView metadata :( NSIndexPath *) indexPath {static NSString * inditifierCell = @ Cell; UITableViewCell * cell = [tableView metadata: inditifierCell]; if (cell = nil) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: inditifierCell];} cell. textLabel. text = [dataArray objectAtIndex: indexPath. row]; return cell;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {NSMutableArray * new = [[NSMutableArray alloc] initWithArray: dataArray]; [new addObject: @ James]; self. dataArray = new; [footView refreshStateNomal]; self. tableView. contentInset = UIEdgeInsetsMake (0, 0, 0, 0);} # pragma mark-kvo // listens to the dataArray to set the position of 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 // call-(void) scrollViewDidScroll (UIScrollView *) scrollView {if (footView. refreshState = RefreshStateNomal & scrollView. contentOffset. y> scrollView. contentSize. height-scrollView. frame. size. height + 70) {[footView succeeded] ;}// call-(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]; [UIView commitAnimations];} @ end


 

Process some events in table:

To test whether the position of footview changes after data is added, a data entry is added when you click cell;

To test whether the page can be dragged for the second time after loading is complete, the foottview stops when the cell is clicked;

 

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.