Xlpagertabstrip: Crash when supplying image to IndicatorInfo

Created on 13 Jan 2017  路  6Comments  路  Source: xmartlabs/XLPagerTabStrip

  • Environment: XLPagerTabStrip, Xcode 8.2.1, iOS 9.3
  • Xcode console output of stack trace: fatal error: unexpectedly found nil while unwrapping an Optional value
  • When implementing protocol IndicatorInfoProvider and returning an instance of IndicatorInfo with an image, a crash occurs when trying set the image to the the imageview of the buttonbarcell.
    Here is a screenshot of where the crash occurs:
    screen shot 2017-01-13 at 3 04 59 am

Here is how I implemented the IndicatorInfoProvider protocol:
screen shot 2017-01-13 at 3 06 30 am

Thanks :]

question appearance

Most helpful comment

How to do this (adding image and label) programmatically? And without Nib file

All 6 comments

Same Issue with me.
Please Help.

Look at ButtonBarViewCell.xib:
It has an outlet for an imageView, but no actual UIImageView was added to the cell.

Thanks!
Adding imageView in the cell and connecting the outlet worked for me.

There are 2 modes, "text only" mode, and "text + image" mode.
If you only need one of those modes, then you're fine, but if you need both modes in the same app, like me, you have to play around with the constraints to support positioning in each mode.

Take a look at how YoutubeExampleViewController is created. Basically it extends from aseButtonBarPagerTabStripViewController which is a generic view controller that allows to specify the bar menu collection cell, in this case YoutubeIconCell.

I didn't document this because it's hard to connect interface builder view controller with a generic view controller class since the vc type is not suggested in the xcode IB editor.

You have to let the library knows how to load the bar item cell by specifying buttonBarItemSpec property.

buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "YoutubeIconCell", bundle: Bundle(for: YoutubeIconCell.self), width: { (cell: IndicatorInfo) -> CGFloat in
     return 55.0
})

we need also to set up the cell by overriding:

override func configure(cell: YoutubeIconCell, for indicatorInfo: IndicatorInfo) {
     cell.iconImage.image = indicatorInfo.image?.withRenderingMode(.alwaysTemplate)
}

Notice that the first parameter type is the base view controller generic type.

the rest is pretty much the same.

Hope it's helps

How to do this (adding image and label) programmatically? And without Nib file

Was this page helpful?
0 / 5 - 0 ratings