xmartlabs / XLPagerTabStrip

Android PagerTabStrip for iOS.
MIT License
6.97k stars 1.33k forks source link

buttonBarView.selectedBar.backgroundColor bad_access #377

Open Stefano1994 opened 7 years ago

Stefano1994 commented 7 years ago
screen shot 2017-05-16 at 16 09 15

It happens in the start of my app running. this is what my ViewController like.

import UIKit
import XLPagerTabStrip

class MainTabBarViewController:ButtonBarPagerTabStripViewController{
    var homeViewController:HomeViewController!
    var voucherViewController:VoucherViewController!
    var goldTopUpViewController:GoldTopUpViewController!

    override func viewDidAppear(_ animated: Bool) {
        let selectedBarHeight: CGFloat = 2

        buttonBarView.selectedBar.frame.origin.y = buttonBarView.frame.size.height - selectedBarHeight
        buttonBarView.selectedBar.frame.size.height = selectedBarHeight

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        settings.style.buttonBarBackgroundColor = UIColor(red: 35/255, green: 171/255, blue: 250/255, alpha: 1.0)
        settings.style.buttonBarItemBackgroundColor = UIColor(red: 35/255, green: 171/255, blue: 250/255, alpha: 1.0)

        settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14)
        settings.style.selectedBarHeight = 2.0
        settings.style.selectedBarBackgroundColor = UIColor.white
        settings.style.buttonBarMinimumLineSpacing = 0
        settings.style.buttonBarItemTitleColor = .black
        settings.style.buttonBarItemsShouldFillAvailiableWidth = true
        settings.style.buttonBarLeftContentInset = 0
        settings.style.buttonBarRightContentInset = 0

        buttonBarView.selectedBar.backgroundColor = UIColor.white
        buttonBarView.backgroundColor = UIColor(red: 35/255, green: 171/255, blue: 250/255, alpha: 1.0)

        changeCurrentIndexProgressive = {[weak self](oldCell:ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage:CGFloat, changeCurrentIndex:Bool, animated:Bool)-> Void in

            guard changeCurrentIndex == true else {return}
            oldCell?.label.textColor = UIColor(red: 25/255, green: 142/255, blue: 209/255, alpha: 1.0)
            newCell?.label.textColor = .white
        }

        //DEVELOPER: set the default child ViewController to be shown first
        moveToViewController(at: 1)

        //DEVELOPER: add threedots to navigationbar
        let image_threedots = UIImage(named: "opt")
        navigationItem.rightBarButtonItem = UIBarButtonItem(image: image_threedots, style: UIBarButtonItemStyle.plain, target: self, action: nil)
    }

    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        homeViewController = UIStoryboard(name: "MainTabBar", bundle: Bundle.main).instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
        goldTopUpViewController = UIStoryboard(name: "MainTabBar", bundle: Bundle.main).instantiateViewController(withIdentifier: "GoldTopUpViewController") as! GoldTopUpViewController
        voucherViewController = UIStoryboard(name: "MainTabBar", bundle: Bundle.main).instantiateViewController(withIdentifier: "VoucherViewController") as! VoucherViewController

        return [goldTopUpViewController!,homeViewController!,voucherViewController!]
    }

}

extension MainTabBarViewController:IMainTabBarView{

}
santiagofm commented 7 years ago

hey @Stefano1994 !

The one thing i see wrong is that all the settings should be set before calling super.viewDidLoad, but that shouldn't cause the bad access anyway. Which version of the library are you using ? Are you instantiating MainTabBarViewController via a Storyboard ? Could you provide some sample code to reproduce the issue ?

Cheers

Stefano1994 commented 7 years ago

I am using ver. '7.0'. Yes I am instantiating it from Storyboard like this let _mainTabBarViewController: MainTabBarViewController? = UIStoryboard(name: "MainTabBar", bundle: Bundle.main).instantiateViewController(withIdentifier: "MainTabBarViewController") as? MainTabBarViewController I have rechecked the storyboard name and the identifier, they were okay. MainTabBarViewController is indeed running because it goes to super.viewDidLoad() but then it was break until it hit the code above and said that it was "bad access". so frustating!

santiagofm commented 7 years ago

I can't see a reason for the crash, it's weird. Could you upload a sample project ? Also, i don't think it will make a difference but could you try using whats on the master branch instead of the latest release ?

santiagofm commented 7 years ago

Ok, so trying to reproduce another issue i was able to reproduce yours =]. Are you using carthage ? How are you connecting the outlets for containerView and buttonBarView ?

everestman27 commented 7 years ago

I also run into a crash issue at buttonBarview Xcode Error: Unknown class ButtonBarView in Interface Builder file.

santiagofm commented 7 years ago

Hey @rajeshmani27, try inputting the Module XLPagerTabStrip for the UICollectionView's custom class.

Cheers

everestman27 commented 7 years ago

Thanks @santiagofm that helped fix the crash. However, I am now running into another issue - the titles I set in the childivewcontrollers by extending the IndicatorInfo protocol, is not getting displayed on the collectionView bar button (followed the above medium article). Any ideas what might be happening - I checked the InstagramExampleViewController and my code seems to be aligned to it. The only difference is I am instantiating my childviewcontroller, a tableviewcontroller, from storyboard. T

Attached the snapshot of my layout in storyboard of the barbuttonView (set background color to yellow) and containerView and how it shows up in the App

xltabbar xltabbar-view
santiagofm commented 7 years ago

Awesome @rajeshmani27 ! As for the new issue, i don't think it's a issue related to the children cause the buttonBarView isn't showing the backgroundColor nor the selectedBar. Would you mind sharing your code so we can take a look?

everestman27 commented 7 years ago

@santiagofm

Code for the custom pagertabviewcontroller & tableviewcontroller below:

import UIKit
import XLPagerTabStrip

class ListingDetailsViewController: ButtonBarPagerTabStripViewController {

    //bar button color
    let purpleInspireColor = UIColor(red:0.13, green:0.03, blue:0.25, alpha:1.0)

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // change selected bar color
        settings.style.buttonBarBackgroundColor = .white
        settings.style.buttonBarItemBackgroundColor = .white
        settings.style.selectedBarBackgroundColor = purpleInspireColor
        settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14)
        settings.style.selectedBarHeight = 2.0
        settings.style.buttonBarMinimumLineSpacing = 0
        settings.style.buttonBarItemTitleColor = .black
        settings.style.buttonBarItemsShouldFillAvailiableWidth = true
        settings.style.buttonBarLeftContentInset = 0
        settings.style.buttonBarRightContentInset = 0

        changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
            guard changeCurrentIndex == true else { return }
            oldCell?.label.textColor = .black
            newCell?.label.textColor = self?.purpleInspireColor
        }

    }

    //MARK: Add Bot, Queue, Active, Completed view controllers  
    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {

        let child1SessionsViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SessionsTableViewController")
        let child2SessionsViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "child2")
        return [child1SessionsViewController, child2SessionsViewController]

    }
}
---
child1TableViewController:

import UIKit
import XLPagerTabStrip

class child1SessionsTableViewController: UITableViewController, IndicatorInfoProvider {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.rowHeight = UITableViewAutomaticDimension
        self.tableView.estimatedRowHeight = 100

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 3
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SessionCell", for: indexPath)

        // Configure the cell...

        return cell
    }

    func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
        return IndicatorInfo(title:"Bot Session")
    }
}
santiagofm commented 7 years ago

@rajeshmani27 try configuring the buttonBar style before calling super.viewDidLoad(). Everything else seems ok to me. Are you instantiating ListingDetailsViewController via Storyboard ?

Lorelei89 commented 6 years ago

Hi guys I'm using as cocapods file

pod 'XLPagerTabStrip', '~> 8.0' use_frameworks! end

post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' end end end

and i;m getting the same error on ButtonBarPagerTabStripSettings class: buttonBarView.backgroundColor = settings.style.buttonBarBackgroundColor ?? buttonBarView.backgroundColor buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor

Is someone having any sollution for this? Kind regards

GuruDev920 commented 5 years ago

Hello, i have a same issue. So i had done upper method. But i can't fix it. Here ie my code.

import UIKit import Foundation import XLPagerTabStrip

class TasksVC: ButtonBarPagerTabStripViewController { override func awakeFromNib() { super.awakeFromNib() } override func viewDidLoad() { // change selected bar color settings.style.buttonBarBackgroundColor = Colour.groupPager settings.style.buttonBarItemBackgroundColor = .clear settings.style.selectedBarBackgroundColor = Colour.white settings.style.selectedBarBackgroundColor = UIColor.white settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 18) settings.style.selectedBarHeight = 2 settings.style.buttonBarMinimumLineSpacing = 10 settings.style.buttonBarItemTitleColor = Colour.white settings.style.buttonBarItemsShouldFillAvailableWidth = true settings.style.buttonBarLeftContentInset = 10 settings.style.buttonBarRightContentInset = 10 settings.style.buttonBarHeight = 80 changeCurrentIndexProgressive = {(oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in guard changeCurrentIndex == true else { return } oldCell?.label.textColor = Colour.black newCell?.label.textColor = Colour.white } super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated)

}
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
}
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
}

override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
    let child_1 = UIStoryboard(name: "Second", bundle: nil).instantiateViewController(withIdentifier: "child1") as! child1
    let child_2 = UIStoryboard(name: "Second", bundle: nil).instantiateViewController(withIdentifier: "child2") as! child2
    let child_3 = UIStoryboard(name: "Second", bundle: nil).instantiateViewController(withIdentifier: "child3") as! child3
    let child_4 = UIStoryboard(name: "Second", bundle: nil).instantiateViewController(withIdentifier: "child4") as! child4
    return [child_1,child_2,child_3,child_4]
}

}

AliShafiee commented 2 years ago

change class name of UICollectionView from buttonBarView to ButtonBarView resolves issue for me. (b -> B)