Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All of a sudden... fatal error: unexpectedly found nil while unwrapping an Optional value #64

Closed
kcfgl opened this issue Jun 3, 2016 · 5 comments

Comments

@kcfgl
Copy link

kcfgl commented Jun 3, 2016

Love this library. Been using it for a while now, but after upgrading cocoapods and reinstalling all the pods, I know am hitting a strange error. Nothing else has changed, but this is now the issue I'm seeing:

cell.checkmarkIcon.hidden = (indexPath.row == selectedIndexPath) ? false : true

Running XCode 7.3.1 and the latest BTNavigationDropdownMenu

Any idea why this is happening? It could certainly be me, but I haven't been able to solve it for some time. Thanks!

kane

@BrianKopp
Copy link

One of those must not be initialized. When is this being called? Before it's UI is initialized?

@kcfgl
Copy link
Author

kcfgl commented Jun 3, 2016

I call setupDropdown() from viewDidLoad()

In setupDropdown() I have this code:

    let items = ["Green Trail", "Orange Trail", "Red Trail", "Yellow Trail"]
    menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, title: "Trails", items: items)
    menuView.cellHeight = 50
    menuView.cellBackgroundColor = self.navigationController?.navigationBar.barTintColor
    menuView.cellSelectionColor = UIColor.cmp_darkHeader()
    menuView.cellTextLabelColor = UIColor.whiteColor()
    menuView.cellTextLabelFont = UIFont(name: "Arvil", size: 22)
    menuView.cellTextLabelAlignment = .Left // .Center // .Right // .Left
    menuView.arrowPadding = 15
    menuView.animationDuration = 0.5
    menuView.maskBackgroundColor = UIColor.blackColor()
    menuView.maskBackgroundOpacity = 0.0
    menuView.didSelectItemAtIndexHandler = {(indexPath: Int) -> () in
        print("Did select item at index: \(indexPath)")
        self.showTrailDetails(indexPath)
    }
    self.navigationItem.titleView = menuView

Nothing has changed at all here or in the way I call it. Thanks for the crazy quick response!

@BrianKopp
Copy link

Can you tell which variable is nil that shouldn't be. Try swapping out some of the variables and see which one is the culprit, e.g. let myCell = cell, let myCellImage = cell.checkMarkIcon, etc., and see which one blows it up.

In other parts of the source, I see "cell?.". Maybe the cell isn't initialized when you get here? I haven't updated my code yet so I don't know if I'd be able to reproduce this.

I don't see anything obviously wrong with your setupDropdown(), which is consistent with this being a new issue post-update.

I'm also not a contributor to the repo, just a fellow fan/user like you :-)

@kcfgl
Copy link
Author

kcfgl commented Jun 3, 2016

Thanks for your help, Brian. The community appreciates it!

I'm not sure if this is helpful, but simply commenting out this line eliminates the error.

//cell.checkmarkIcon.hidden = (indexPath.row == selectedIndexPath) ? false : true

For my specific application, not showing the checkmark isn't an issue. In fact I would prefer it that way actually.

I'll keep messing around and see if I see anything else.

Thanks again for your help!

ifndefgt pushed a commit to ifndefgt/BTNavigationDropdownMenu that referenced this issue Jun 9, 2016
ifndefgt added a commit to ifndefgt/BTNavigationDropdownMenu that referenced this issue Jun 14, 2016
Fixed Issue PhamBaTho#64 Crash While Unwrapping SelectedIndex
@PhamBaTho
Copy link
Owner

@kcfgl yeah, the reason is initial title "Trails" is not in the items array. Then, this line of code causes the crash you got: self.selectedIndexPath = (items as! [String]).indexOf(title).

The PR #66 fixed this issues.

PhamBaTho added a commit that referenced this issue Jun 27, 2016
Fixed issue #64: Crash while unwrapping selectedIndexPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants