#import "LYBaseVC.h"
@interface RankingVC : LYBaseVC
@end
//控制器和view分离
#import "RankingVC.h"
#import "RankingView.h"
@interface RankingVC ()<rankDelegate>
@property (nonatomic,strong)NSMutableArray * dataArray;
@property (nonatomic,strong)RankingView * rankView;
@end
@implementation RankingVC
- (void)viewDidLoad {
[superviewDidLoad];
[self initUI];
}
-(void)initUI{
//添加Tableview
RankingView * rankView = [[RankingViewalloc]initRankingView];
rankView.rankingDelegate = self;
[self.viewaddSubview:rankView];
self.rankView = rankView;
}
-(void)getNetData{
}
#pragma mark--rankingDelegate
-(void)refrshranktableView{
// WEAKSELF();
// NSDictionary * dic = @{@"token":[SPMobileApplication sharedInstance].loginUser.token,
// @"page":@"1",
// @"pageSize":@"50"
// };
// NSString * urlStr = StringAddString(TESTBASEURL, @"/api/user/experienceRank");
// [NetManager postUrl:urlStr parameter:dic succeed:^(id BackData) {
// if ([BackData[@"status"] integerValue]==1) {
// weakSelf.dataArray = [RankingModel mj_objectArrayWithKeyValuesArray:BackData[@"result"]];
// [weakSelf.rankView refrshRankingtableView:weakSelf.dataArray]; //请求到数据后调用View的方法刷新Tableview的数据
// }
//
// } failed:^(NSError *error) {
// [[AXProgressHUDHelper getInstance] showTextWithStatus:@"网络故障" onView:self.view];
// }];
}
-(void)poptolastvc{
[self.navigationControllerpopViewControllerAnimated:YES];
}
-(NSMutableArray *)dataArray{
if (_dataArray ==nil) {
_dataArray =[NSMutableArraynew];
}
return_dataArray;
}
@end
#import <UIKit/UIKit.h>
@protocol rankDelegate <NSObject>
@optional
-(void)refrshranktableView;
-(void)poptolastvc;
@end
@interface RankingView : UIView
-(instancetype)initRankingView;
-(void)refrshRankingtableView:(NSMutableArray*)rankArray;
@property (nonatomic,weak)id <rankDelegate> rankingDelegate;
@end
*****************#import "RankingView.h"
#import "RankingViewCell.h"
#import <MJRefresh.h>
#import "Header.h"
static NSString *const reuseIdentifier = @"RankingViewCell";
@interface RankingView () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)NSMutableArray * rankingArray;
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)UIView * tableHeaderView;
@end
@implementation RankingView
-(instancetype)initRankingView{
self = [selfinitWithFrame:CGRectMake(0,0,WIDTH ,HEIGHT)];
if (self) {
[selfcreateHeaderView];
[self createUI];
[selfrefrshtableView];
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [superinitWithFrame:frame];
if (self) {
self.backgroundColor = [UIColorredColor];
}
return self;
}
-(void)createUI{
self.tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0, WIDTH,HEIGHT) style:UITableViewStylePlain];
self.tableView.delegate =self;
self.tableView.dataSource =self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.estimatedSectionHeaderHeight =0;
self.tableView.estimatedSectionFooterHeight =0;
self.tableView.rowHeight =64;
[selfaddSubview:self.tableView];
self.tableView.tableHeaderView =self.tableHeaderView;
// tableView 偏移20/64适配
if (@available(iOS11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
}else {
//self.automaticallyAdjustsScrollViewInsets = NO;
}
[self.tableViewregisterClass:[RankingViewCellclass] forCellReuseIdentifier:reuseIdentifier];
}
-(void)refrshtableView{
self.tableView.header = [MJRefreshNormalHeaderheaderWithRefreshingTarget:selfrefreshingAction:@selector(loadNewData)];
[self.tableView.headerbeginRefreshing];
}
-(void)loadNewData{
NSLog(@"refrsh");
if (self.rankingDelegate && [self.rankingDelegaterespondsToSelector:@selector(refrshranktableView)]) {
[self.rankingDelegaterefrshranktableView];//刷新的时候调用代理方法请求数据
}
}
//在控制器页面请求到数据后调用这个方法刷新tableview
-(void)refrshRankingtableView:(NSMutableArray*)rankArray
{
[selfrefrshtableHeaderView];
[self.tableViewreloadData];
[self.tableView.headerendRefreshing];
}
-(void)refrshtableHeaderView{
}
-(void) createHeaderView
{
}
-(void)poplastvc{
NSLog(@"pop");
if (self.rankingDelegate && [self.rankingDelegaterespondsToSelector:@selector(poptolastvc)]) {
[self.rankingDelegatepoptolastvc];
}
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
returnself.rankingArray.count -3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
RankingViewCell * cell = (RankingViewCell *)[tableViewdequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[RankingViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:reuseIdentifier];
}
if (self.rankingArray.count>0) {
//设置cell的数据
}
return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return0.0001f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return0.0001f;
}
#pragma mark--懒加载
-(NSMutableArray *)rankingArray{
if (_rankingArray ==nil) {
_rankingArray = [NSMutableArraynew];
}
return_rankingArray;
}
@end
#import <UIKit/UIKit.h>
@interface RankingViewCell : UITableViewCell
-(void)setcellWith:(NSDictionary *)dict;
@end
#import "RankingViewCell.h"
@implementation RankingViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle =UITableViewCellSelectionStyleNone;
[self createUI];
}
return self;
}
-(void)createUI{
//添加子控件
}
-(void)setcellWith:(NSDictionary *)dict{
//设置cell的数据
}
@end