Skip to content

Commit

Permalink
add reload.
Browse files Browse the repository at this point in the history
  • Loading branch information
yongyuandouneng committed Aug 5, 2018
1 parent aa8e96e commit 0a246ef
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 27 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -63,7 +63,10 @@
## CocoaPods更新日志

```
• 2018-07-27 (tag 0.1.3): 新增置顶API, 插入、删除、调整顺序控制器的API。
• 2018-07-27 (tag 0.1.3 ~ 0.1.7): 添加reloadData方法、自定义缓存Key可配置相同title、优化QQ联系人悬浮布局
• 2018-07-27 (tag 0.1.3): 新增置顶API, 插入、删除、调整顺序控制器的API
• 2018-07-23 (tag 0.1.2): 新增可以添加 ScrollMenu ButtonItem image
Expand Down
2 changes: 1 addition & 1 deletion YNPageViewController.podspec
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "YNPageViewController"
s.version = "0.1.6"
s.version = "0.1.7"
s.summary = "特斯拉组件、多页面嵌套滚动、悬停效果、QQ联系人"

# This description is used to generate tags and improve search results.
Expand Down
Expand Up @@ -93,11 +93,11 @@

@interface YNPageViewController : UIViewController
/// 配置信息
@property (nonatomic, strong, readonly) YNPageConfigration *config;
@property (nonatomic, strong) YNPageConfigration *config;
/// 控制器数组
@property (nonatomic, strong, readonly) NSMutableArray<__kindof UIViewController *> *controllersM;
/// 标题数组
@property (nonatomic, strong, readonly) NSMutableArray<NSString *> *titlesM;
@property (nonatomic, strong) NSMutableArray<__kindof UIViewController *> *controllersM;
/// 标题数组 默认 缓存 key 为 title 可通过数据源代理 进行替换
@property (nonatomic, strong) NSMutableArray<NSString *> *titlesM;
/// 菜单栏
@property (nonatomic, strong) YNPageScrollMenuView *scrollMenuView;
/// 背景ScrollView
Expand Down Expand Up @@ -149,13 +149,24 @@
*/
- (void)removeSelfViewController;

/**
刷新数据页面、所有View、菜单栏、headerView - 默认移除缓存控制器
刷新菜单栏配置 标题数组
e.g: vc.config = ...
vc.titlesM = [self getArrayTitles].mutableCopy;
如果需要重新走控制器的ViewDidLoad方法则需要重新赋值 controllers
e.g:
vc.controllersM = [self getArrayVCs].mutableCopy;
*/
- (void)reloadData;

/**
选中页码
@param pageIndex 页面下标
*/
- (void)setSelectedPageIndex:(NSInteger)pageIndex;


/**
更新菜单栏标题
@param title 标题
Expand Down Expand Up @@ -210,4 +221,6 @@
*/
- (void)scrollToTop:(BOOL)animated;



@end
Expand Up @@ -21,12 +21,6 @@ @interface YNPageViewController () <UIScrollViewDelegate, YNPageScrollMenuViewDe
@property (nonatomic, strong) YNPageHeaderScrollView *headerBgView;
/// 页面ScrollView
@property (nonatomic, strong) YNPageScrollView *pageScrollView;
/// 配置信息
@property (nonatomic, strong, readwrite) YNPageConfigration *config;
/// 控制器数组
@property (nonatomic, strong, readwrite) NSMutableArray<__kindof UIViewController *> *controllersM;
/// 标题数组
@property (nonatomic, strong, readwrite) NSMutableArray<NSString *> *titlesM;
/// 背景ScrollView
@property (nonatomic, strong, readwrite) YNPageScrollView *bgScrollView;
/// 展示控制器的字典
Expand Down Expand Up @@ -66,12 +60,7 @@ - (void)viewDidLoad {
[super viewDidLoad];
[self initData];
[self setupSubViews];

if (self.pageIndex == 0) {
[self initViewControllerWithIndex:self.pageIndex];
} else {
[self setSelectedPageIndex:self.pageIndex];
}
[self setSelectedPageIndex:self.pageIndex];
}

#pragma mark - Initialize Method
Expand Down Expand Up @@ -393,13 +382,44 @@ - (void)setSelectedPageIndex:(NSInteger)pageIndex {
if (pageIndex > self.controllersM.count - 1) return;

CGRect frame = CGRectMake(self.pageScrollView.yn_width * pageIndex, 0, self.pageScrollView.yn_width, self.pageScrollView.yn_height);
if (frame.origin.x == self.pageScrollView.contentOffset.x) {
[self scrollViewDidScroll:self.pageScrollView];
} else {
[self.pageScrollView scrollRectToVisible:frame animated:NO];
}

[self.pageScrollView scrollRectToVisible:frame animated:NO];

[self scrollViewDidEndDecelerating:self.pageScrollView];

}

- (void)reloadData {

[self checkParams];

self.pageIndex = self.pageIndex < 0 ? 0 : self.pageIndex;
self.pageIndex = self.pageIndex >= self.controllersM.count ? self.controllersM.count - 1 : self.pageIndex;

for (UIViewController *vc in self.displayDictM.allValues) {
[self removeViewControllerWithChildVC:vc];
}
[self.displayDictM removeAllObjects];

[self.cacheDictM removeAllObjects];

[self.headerBgView removeFromSuperview];
[self.bgScrollView removeFromSuperview];
[self.pageScrollView removeFromSuperview];

[self.scrollMenuView removeFromSuperview];

[self.originInsetBottomDictM removeAllObjects];

[self setupSubViews];

[self setSelectedPageIndex:self.pageIndex];

}

- (void)updateMenuItemTitle:(NSString *)title index:(NSInteger)index {
if (index < 0 || index > self.titlesM.count - 1 ) return;
if (title.length == 0) return;
Expand Down
Expand Up @@ -56,7 +56,8 @@ - (void)rightButtonOnClick:(UIBarButtonItem *)item event:(UIEvent *)event {
@"更新菜单栏标题",
@"添加页面",
@"删除页面",
@"调整标题顺序"] doneBlock:^(NSInteger selectedIndex) {
@"调整标题顺序",
@"reload"] doneBlock:^(NSInteger selectedIndex) {
switch (selectedIndex) {
case 0:
{
Expand Down Expand Up @@ -87,6 +88,14 @@ - (void)rightButtonOnClick:(UIBarButtonItem *)item event:(UIEvent *)event {
[self replaceTitlesArrayForSort:@[@"帽子", @"衣服", @"鞋子"]];
}
break;
case 5:
{
self.titlesM = @[@"刷新页面", @"棒球", @"篮球"].mutableCopy;
self.config.menuHeight = 100;
self.pageIndex = 0;
[self reloadData];
}
break;
}
} dismissBlock:nil];
}
Expand Down
Expand Up @@ -40,6 +40,7 @@ - (void)viewDidLoad {
[self.tableView reloadData];
});
[self addTableViewRefresh];

}

- (void)viewWillAppear:(BOOL)animated {
Expand Down
Expand Up @@ -86,7 +86,7 @@ + (NSArray *)getArrayVCs {
}

+ (NSArray *)getArrayTitles {
return @[@"鞋子", @"衣服", @"衣服"];
return @[@"鞋子", @"衣服", @"帽子"];
}

#pragma mark - Private Function
Expand Down
Expand Up @@ -40,6 +40,7 @@ - (void)viewDidLoad {
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [self.tableView setContentOffset:CGPointMake(0, 240)];
// });

}

- (void)viewWillAppear:(BOOL)animated {
Expand Down Expand Up @@ -70,9 +71,9 @@ - (void)addTableViewRefresh {
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (int i = 0; i < 30; i++) {
[self.dataArray addObject:@""];
[weakSelf.dataArray addObject:@""];
}
[self.tableView reloadData];
[weakSelf.tableView reloadData];
[weakSelf.tableView.mj_footer endRefreshing];
});
}];
Expand Down
Expand Up @@ -87,12 +87,12 @@ + (instancetype)suspendTopPausePageVC {

vc.bgScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

NSInteger refreshPage = vc.pageIndex;
NSInteger refreshPage = weakVC.pageIndex;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

/// 取到之前的页面进行刷新 pageIndex 是当前页面
YNSuspendTopPauseBaseTableViewVC *vc2 = vc.controllersM[refreshPage];
YNSuspendTopPauseBaseTableViewVC *vc2 = weakVC.controllersM[refreshPage];
[vc2.tableView reloadData];

if (kOpenRefreshHeaderViewHeight) {
Expand Down

0 comments on commit 0a246ef

Please sign in to comment.