I've got a UIViewController which is also the UITableViewDelegate, amongst other things, for a UITableView, created in FirstView.xib
@interface FirstViewController : UIViewController <
UITextFieldDelegate,
UITableViewDelegate,
UITableViewDataSource
> {
UITableView *searchResults; // this is the property for the table view
...
}
I want this table view to make use of PullToRefresh: https://github.com/leah/PullToRefresh, but the documentation there only explains how to make use of the class as a sub class of the view controller
#import "PullRefreshTableViewController.h"
@interface DemoTableViewController : Pu开发者_运维技巧llRefreshTableViewController {
NSMutableArray *items;
}
My app uses a Tab bar as the root view controller, can anyone explain to me how I can make the UITableView into a PullRefreshTableView? When I don't have a UITableViewController to edit?
The secret is in the scroll view delegate methods which you can already respond to since you are acting as the tables delegate. This article provides a good start to create your own pull to refresh.
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
This will let you know when the user starts dragging the scrollview so you can begin checking whether to refresh or not.- (void)scrollViewDidScroll:(UIScrollView *)scrollView
This allows you to make necessary transitions while scrolling (mainly swapping text and flipping the arrow)- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
This is where you decide if the user has dragged far enough down to start the refresh.
Use this API
It works fine with UIViewController
精彩评论