Skip to content

Commit

Permalink
修复初始化时hotSearches为nil,稍后设置导致hotSearchStyle失效问题
Browse files Browse the repository at this point in the history
初始化时hotSearches为nil,稍后设置导致hotSearchStyle失效,详情见:https://github.com/iphone
5solo/PYSearch/issues/19
  • Loading branch information
ko1o committed Nov 22, 2016
1 parent b2482ab commit 4efd5e2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions PYSearch/PYSearchViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ - (void)viewWillAppear:(BOOL)animated
self.baseSearchTableView.tableHeaderView.py_height = 0;
self.baseSearchTableView.tableHeaderView.hidden = YES;
}

// 刷新热门搜索
[self setHotSearches:self.hotSearches];
// 刷新热门搜索Style
[self setHotSearchStyle:self.hotSearchStyle];
// 刷新搜索历史Style
[self setSearchHistoryStyle:self.searchHistoryStyle];
}

/** 视图完全显示 */
Expand Down Expand Up @@ -458,7 +465,7 @@ - (void)setupHotSearchRankTags
self.rankViews = rankViewM;

// 计算位置
for (int i = 0; i < self.hotSearchTags.count; i++) { // 每行两个
for (int i = 0; i < self.rankViews.count; i++) { // 每行两个
UIView *rankView = self.rankViews[i];
rankView.py_x = (PYMargin + rankView.py_width) * (i % 2);
rankView.py_y = rankView.py_height * (i / 2);
Expand Down Expand Up @@ -492,6 +499,7 @@ - (void)setupSearchHistoryTags
self.baseSearchTableView.tableFooterView = nil;
// 添加搜索历史头部
self.searchHistoryHeader.py_y = self.hotSearches.count > 0 ? CGRectGetMaxY(self.hotSearchTagsContentView.frame) + PYMargin * 1.5 : 0;
self.emptyButton.py_y = self.searchHistoryHeader.py_y - PYMargin * 0.5;
self.searchHistoryTagsContentView.py_y = CGRectGetMaxY(self.emptyButton.frame) + PYMargin;
// 添加和布局标签
self.searchHistoryTags = [self addAndLayoutTagsWithTagsContentView:self.searchHistoryTagsContentView tagTexts:[self.searchHistories copy]];
Expand All @@ -518,7 +526,8 @@ - (NSArray *)addAndLayoutTagsWithTagsContentView:(UIView *)contentView tagTexts:
CGFloat countCol = 0;

// 调整布局
for (UILabel *subView in tagsM) {
for (int i = 0; i < contentView.subviews.count; i++) {
UILabel *subView = contentView.subviews[i];
// 当搜索字数过多,宽度为contentView的宽度
if (subView.py_width > contentView.py_width) subView.py_width = contentView.py_width;
if (currentX + subView.py_width + PYMargin * countRow > contentView.py_width) { // 得换行
Expand Down Expand Up @@ -550,6 +559,7 @@ - (void)setHotSearchTags:(NSArray<UILabel *> *)hotSearchTags
}
_hotSearchTags = hotSearchTags;
}

- (void)setSearchBarBackgroundColor:(UIColor *)searchBarBackgroundColor
{
_searchBarBackgroundColor = searchBarBackgroundColor;
Expand Down

0 comments on commit 4efd5e2

Please sign in to comment.