This is my fifth day of the August Challenge
The introduction
Requirements:
1. Add payment reward notification to THE ERP APP of iOS retail version
2, notification information (timing xx point; Historical information available)
2021-04-29 Dear business, you participate in the XXX incentive activity, yesterday participated in 10 successful, a total of 1 yuan incentive!
Because the message list has a large amount of data, to improve user experience, it is necessary to use paging loading to display data
I. Integrate the drop-down refresh control
1.1 Define relevant paging properties
- Paging properties
@property (nonatomic , assign) NSInteger pageNum;// Current page number
@property (nonatomic , assign) NSInteger pageCount;/ / the total number of pages
@property (nonatomic , assign) BOOL isfooterRereshing;
// Display number per page...
Copy the code
- Event and data properties in the VM
@property (nonatomic.strong) NSMutableArray *datas;
@property (nonatomic.strong) RACSubject *reloadSubject;
@property (nonatomic.strong) RACSubject *ShowNoviewSubject;
@property (nonatomic.strong) RACSubject *hidenNoviewSubject;
Copy the code
1.2 Listening for drop-down and drop-down events
- VC listens for and handles drop – down and pull – up events
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRereshing)];
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRereshing)];
Copy the code
- Handle pull-up data events
/** Is used to pull down the mark to make */
@property (nonatomic , assign) BOOL isfooterRereshing;
- (void)footerRereshing
{
self.isfooterRereshing = YES;
if ((_pageNum + 1) > _pageCount) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
return;
}
_pageNum = _pageNum + 1;
[self doorRequest];
}
Copy the code
- Handle the drop-down refresh data event
- (void)headerRereshing
{
self.isfooterRereshing = NO;
[_doorArr removeAllObjects];// Remove data, can be requested successfully, then remove
_pageNum = 1;
[self doorRequest];
}
Copy the code
1.3 Processing of request data
The refresh view is turned off on success and failure
[weakSelf.vcView.tableView.mj_footer endRefreshing];
[weakSelf.vcView.tableView.mj_header endRefreshing];
Copy the code
The complete code quality: kunnan.blog.csdn.net/article/det…
II. IOS implements more perceptual pull-up loading
UITableViewDataSourcePrefetching
// this protocol can provide information about cells before they are displayed on screen.
@protocol UITableViewDataSourcePrefetching <NSObject>
@required
// indexPaths are ordered ascending by geometric distance from the table view
- (void)tableView:(UITableView *)tableView prefetchRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
@optional
// indexPaths that previously were considered as candidates for pre-fetching, but were not actually used; may be a subset of the previous call to -tableView:prefetchRowsAtIndexPaths:
- (void)tableView:(UITableView *)tableView cancelPrefetchingForRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
@end
Copy the code
Other implementation ideas: listen for changes in the contentOffset of scrollView through KVO
MJRefreshAutoFooter triggerAutomaticallyRefreshPercent has a special attribute to do automatic refresh
#import "MJRefreshFooter.h"
NS_ASSUME_NONNULL_BEGIN
@interface MJRefreshAutoFooter : MJRefreshFooter
/** Whether to refresh automatically (default: YES) */
@property (assign.nonatomic.getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
/* refresh automatically when the bottom controls are present (default is 1.0, meaning the bottom controls are present in full) */
@property (assign.nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("Please use triggerAutomaticallyRefreshPercent attributes");
/* refresh automatically when the bottom controls are present (default is 1.0, meaning the bottom controls are present in full) */
@property (assign.nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
/** The number of times the trigger is automatically triggered. The default is 1 and only applies when dragging a ScrollView. If -1, the trigger is infinite */
@property (nonatomic) NSInteger autoTriggerTimes;
@end
Copy the code
III. Case: SINA Weibo API (obtaining user weibo data)
Download.csdn.net/download/u0…
- Integrated drop-down refresh control: the drop-down refresh HWHomeTableViewController
- Get number of unread messages: HWHomeTableViewController
- Encapsulate the title button :HWTitleButton
see also
For more content, please pay attention to the official account: iOS Reverse