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

Crash error in Xcode8 swift3 #47

Closed
skywalkerlw opened this issue Sep 28, 2016 · 17 comments
Closed

Crash error in Xcode8 swift3 #47

skywalkerlw opened this issue Sep 28, 2016 · 17 comments

Comments

@skywalkerlw
Copy link

it crashes if you directly use a local variable "let dropDown = DropDown()", rather than assigning dropDown as a property. However it works in Xcode7.3.

@leizard
Copy link

leizard commented Sep 30, 2016

Seems like I have the same issue. Could you please tell more about "assigning dropDown as a property". I don't quite get that.

@leizard
Copy link

leizard commented Sep 30, 2016

screen shot 2016-09-29 at 18 15 52

This is the error that I had. Is it the same to yours ?

@skywalkerlw
Copy link
Author

yes, exactly the same

@skywalkerlw
Copy link
Author

by the way, if you have codes in extension via objc_setAssociatedObject, you will not be able to dropdown list ,but no crash happens

@leizard
Copy link

leizard commented Sep 30, 2016

I finally make it work. Instead of use let dropDown = DropDown() in my button's IBAction scope. I create local variable let dropDown = DropDown() in my View Controller. then in my button IBAction function, I just init the data source, anchor view and finally show it. Now it works like a charm :D

@kevin-hirsch
Copy link
Collaborator

Hello @leizard and @wangbourne,

this is not new to Xcode 8 and Swift 3, every DropDown instance has no direct superview and is not retained by its anchorView (note that anchorView can be nil, for the DropDown to be centered on the screen). Thus, it has to be retained by something else, usually the class instance.

@yesh0907
Copy link

yesh0907 commented Oct 13, 2016

@leizard I tried your solution however it didn't work. I keep getting the same error. Here is my code

let dropDown = DropDown()
@IBOutlet weak var breadButton: UIButton!
let breads = ["Multigrain", "Honey Oat", "Italian", "Hearty Italian", "Paramesan Oregano", "Wrap", "Flatbread"]

@IBAction func showBread(_ sender:AnyObject) {
    dropDown.anchorView = view

    dropDown.dataSource = breads

    dropDown.show()
}

override func viewDidLoad() {
    super.viewDidLoad()

    dropDown.bottomOffset = CGPoint(x: 0, y: breadButton.bounds.height)
    dropDown.selectionAction = { [weak self] (index: Int, item: String) in
        self?.breadButton.setTitle(item, for: .normal)
    }

    dropDown.backgroundColor = UIColor(red: 32/255, green: 152/255, blue: 93/255, alpha: 1.0)
    dropDown.textColor = UIColor.white

    dropDown.selectionBackgroundColor = UIColor(red: 24/255, green: 138/255, blue: 82/255, alpha: 1.0)
}

Can anyone help? Ty.

@Luccifer
Copy link

Luccifer commented Nov 5, 2016

Bump, same problem

UPD:

Tried to change 484L in DropDown.swift to
DispatchQueue.main.async { void in
self.tableView.flashScrollIndicators()
}

Looks like it works for now

@AdamLenda
Copy link

Same issue

@AdamLenda
Copy link

I've been coding for 20 years and I just spent 4 hours struggling with your code. Either your documentation or your code sucks.

@ChandraNaveen
Copy link

make your dropdown instance global.It works.

@Luccifer
Copy link

you mean public static?

@ChandraNaveen
Copy link

just make it global to your class.

@jigs611989
Copy link

jigs611989 commented Feb 24, 2017

Make it optional
Example:
In ViewController File
let dropDown: DropDown?

then in viewDidLoad function

override func viewDidLoad() {
  super.viewDidLoad()
  dropDown = DropDown()
}

@NonAtomicFunk
Copy link

Hello, @kevin-hirsch

I'm having the very same problem while flipping TableViewControllers using following method.
None of solutions listed above helps me out.
Please advise.

public lazy var orderedViewControllers: [UIViewController] = {
return [self.controller(cls: FirstPageTableViewControllerStatic.self),
self.controller(cls: SecondPageTableViewController.self)]
}() as! [UITableViewController]

@HemantRMali
Copy link

HemantRMali commented Jul 21, 2017

Make it optional, this will work.
let dropDown: DropDown?

@kevin-hirsch
Copy link
Collaborator

Hello everyone!
Sorry for the late response.
I've pushed a new commit that should fix this problem (80a125b on master)

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

10 participants