代码块收藏
2020-08-27 本文已影响0人
奶茶大叔
/**<#Description#>*/
@property (nonatomic, assign) <#type#> <#name#>
/**<#Description#>*/
@property (nonatomic, copy) <#type#> *<#name#>
/**<#Description#>*/
@property (nonatomic, strong) <#type#> *<#name#>
//! <#Description#>
#pragma mark - <#name#>
// ==TableView==
<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.tableView];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.tableView.frame = self.view.bounds;
}
- (void)loadData:(NSInteger)startNum
{
[self POST:<#URL#> params:^(NSMutableDictionary *params, ZYNetworkToolConfig *config) {
params.setObjectForKey(@(startNum), @"startNum")
.setObjectForKey(@(pageSize), @"pageSize")
.setObjectForKey(<#value#>, <#key#>);
config.header = self.tableView.mj_header;
config.footer = self.tableView.mj_footer;
} success:^(id json) {
if (!startNum) {
[self.dataSource removeAllObjects];
}
NSArray * modelList=[<#model#> mj_objectArrayWithKeyValuesArray:[json arrayForKey:@"data"]];
[self.dataSource addObjectsFromArray:modelList];
self.tableView.dataSourceCount = self.dataSource.count;
[self.tableView reloadData]
} failure:^(NSInteger code, NSString *info) {
[self showTip:info];
self.tableView.dataSourceCount = self.dataSource.count;
} error:^(NSError *error) {
self.tableView.dataSourceCount = self.dataSource.count;
}];
}
#pragma mark - dataSource and delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#(nonnull NSString *)#>];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#pragma mark - lazy
- (UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.rowHeight = 44;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = kLBColor_F5F5F5;
[_tableView registerClass:[<#class#> class] forCellReuseIdentifier:<#identifier#>];
[_tableView registerNib:[UINib nibWithNibName:<#name#> bundle:nil] forCellReuseIdentifier:<#identifier#>];
_tableView.tableHeaderView = nil;
ZYWeakSelf
_tableView.mj_header = [LBRefreshGifHeader headerWithRefreshingBlock:^{
ZYStrongSelf
[self loadData:0];
}];
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
ZYStrongSelf
[self loadData:self.dataSource.count];;
}];
[_tableView.mj_header beginRefreshing];
}
return _tableView;
}
- (NSMutableArray *)dataSource
{
if (!_dataSource) {
_dataSource = [NSMutableArray array];
}
return _dataSource;
}