Skip to content

Commit

Permalink
fix the bug that cause the header view cannot be dropped down after r…
Browse files Browse the repository at this point in the history
…eloadData
  • Loading branch information
Jiar committed May 8, 2020
1 parent 522901b commit ca0d1c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Example/Base/BaseTransparentSlideViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import UIKit
import SegementSlide

class BaseTransparentSlideViewController: TransparentSlideViewController {

private var selectedIndex: Int? = nil

override var switcherConfig: SegementSlideSwitcherConfig {
return ConfigManager.shared.switcherConfig
Expand Down Expand Up @@ -70,7 +72,14 @@ class BaseTransparentSlideViewController: TransparentSlideViewController {
}

@objc private func reloadAction() {
selectedIndex = currentIndex
reloadData()
if let selectedIndex = selectedIndex {
scrollToSlide(at: selectedIndex, animated: false)
} else {
scrollToSlide(at: 1, animated: false)
}
selectedIndex = nil
}

@objc private func moreAction() {
Expand Down
2 changes: 1 addition & 1 deletion Source/Content/SegementSlideContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public class SegementSlideContentView: UIView {
/// otherwise, none of them will be selected.
/// However, if an item was previously selected, it will be reSelected.
public func reloadData() {
selectedIndex = nil
clearAllReusableViewControllers()
updateScrollViewContentSize()
updateSelectedIndex()
}

/// select one item by index
Expand Down
2 changes: 1 addition & 1 deletion Source/Segement/SegementSlideSwitcherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class SegementSlideSwitcherView: UIView {
/// otherwise, none of them will be selected.
/// However, if an item was previously selected, it will be reSelected.
public func reloadData() {
selectedIndex = nil
for titleButton in titleButtons {
titleButton.removeFromSuperview()
titleButton.frame = .zero
Expand Down Expand Up @@ -107,7 +108,6 @@ public class SegementSlideSwitcherView: UIView {
indicatorView.backgroundColor = innerConfig.indicatorColor
layoutTitleButtons()
reloadBadges()
updateSelectedIndex()
}

/// reload all badges in `SegementSlideSwitcherView`
Expand Down

0 comments on commit ca0d1c7

Please sign in to comment.