Files
keyboard/keyBoard/Class/Shop/VC/KBShopItemVC.m
2025-11-09 13:56:13 +08:00

142 lines
4.3 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// KBShopItemVC.m
// keyBoard
//
// Created by Mac on 2025/11/9.
//
#import "KBShopItemVC.h"
#import <MJRefresh/MJRefresh.h>
@interface KBShopItemVC ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@end
@implementation KBShopItemVC
- (void)viewDidLoad {
[super viewDidLoad];
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.tableFooterView = [UIView new];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
[self.view addSubview:self.tableView];
__weak typeof(self)weakSelf = self;
if (self.isNeedHeader) {
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.tableView.mj_header endRefreshing];
});
}];
}
if (self.isNeedFooter) {
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf.dataSource addObject:@"加载更多成功"];
[weakSelf.tableView reloadData];
[weakSelf.tableView.mj_footer endRefreshing];
});
}];
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
} else {
//列表的contentInsetAdjustmentBehavior失效需要自己设置底部inset
// self.tableView.contentInset = UIEdgeInsetsMake(0, 0, UIApplication.sharedApplication.keyWindow.jx_layoutInsets.bottom, 0);
}
[self beginFirstRefresh];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.tableView.frame = self.view.bounds;
}
- (void)beginFirstRefresh {
if (!self.isHeaderRefreshed) {
[self beginRefreshImmediately];
}
}
- (void)beginRefreshImmediately {
if (self.isNeedHeader) {
[self.tableView.mj_header beginRefreshing];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.isHeaderRefreshed = YES;
[self.tableView reloadData];
[self.tableView.mj_header endRefreshing];
});
}else {
self.isHeaderRefreshed = YES;
[self.tableView reloadData];
}
}
#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (!self.isHeaderRefreshed) {
return 0;
}
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = self.dataSource[indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// DetailViewController *detailVC = [[DetailViewController alloc] init];
// detailVC.infoString = self.dataSource[indexPath.row];
// [self.navigationController pushViewController:detailVC animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
!self.scrollCallback ?: self.scrollCallback(scrollView);
}
#pragma mark - JXPagingViewListViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.tableView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)listWillAppear {
NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}
- (void)listDidAppear {
NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}
- (void)listWillDisappear {
NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}
- (void)listDidDisappear {
NSLog(@"%@:%@", self.title, NSStringFromSelector(_cmd));
}
@end