XLPagerTabStrip icon indicating copy to clipboard operation
XLPagerTabStrip copied to clipboard

Current index inside child class.

Open vanjaruzic opened this issue 7 years ago • 3 comments

How to get current index inside child class, which, in my case, inherits UITableViewController? Other answers for similar questions didn't helped me...

Thanks for help in advance, cheers.

vanjaruzic avatar Sep 07 '17 22:09 vanjaruzic

Have you found answer to this?

junweimah avatar Feb 06 '18 09:02 junweimah

@junweimah

Use

public var changeCurrentIndexProgressive: ((_ oldCell: ButtonBarViewCell?, _ newCell: ButtonBarViewCell?, _ progressPercentage: CGFloat, _ changeCurrentIndex: Bool, _ animated: Bool) -> Void)?

inside your PagerVC viewDidLoad. Inside closure you can get child's current index every time.

Example:

override func viewDidLoad() {
        super.viewDidLoad()
        
        changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
            guard changeCurrentIndex == true else { return }

            print(self.currentIndex)

        }
    }

vanjaruzic avatar Feb 07 '18 11:02 vanjaruzic

@junweimah

Use

public var changeCurrentIndexProgressive: ((_ oldCell: ButtonBarViewCell?, _ newCell: ButtonBarViewCell?, _ progressPercentage: CGFloat, _ changeCurrentIndex: Bool, _ animated: Bool) -> Void)?

inside your PagerVC viewDidLoad. Inside closure you can get child's current index every time.

Example:

override func viewDidLoad() {
        super.viewDidLoad()
        
        changeCurrentIndexProgressive = { (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
            guard changeCurrentIndex == true else { return }

            print(self.currentIndex)

        }
    }

print(self.currentIndex) it is returning some random indexes, not working

Arshad-iOSDeveloper avatar Oct 04 '23 05:10 Arshad-iOSDeveloper