Closed manzznam closed 9 years ago
Hi, please, check your origin
. I belive it should be not sender.superview!.superview
(most likely it nil
) but sender.superview
.
Sorry that doesn't work neither. In my project i use a ContainerViewController as the window!.rootViewController. In the container i create a navigationController: mainNavigationController = UINavigationController(rootViewController: mainViewController). The mainViewController contains the Button for displaying the picker. Probably my views are different from the example and so is my origin then. But how do i know which is the right origin? Has the origin to be the same view where the picker is shown?
Usually origin should be just the view, that call this picker. Such complex sender.superview!.superview
expression should be only when you present picker on iPad from tableviewcell
- to set correct position of the picker.
So, try to use just origin
in your case. And let me know, if you still this error. Also, check, that you sender is not nil
!
What do you exactly mean with just use "origin"? I mean what parameter should i use for "origin"?
Any UIView
on the screen. In your case sender.view
In my case sender is UIButton and does not have a property "sender.view". I tried also "view" and "self.view" as origin but i get the same error...
oops, i mean just sender
(cuz UIButton is subclass of view). Is it works?
No that doesn't work either. I just tried to access a variable in your original Swift-Example project (fresh checkout) and there i get the same error. Could you provide some sample code how i can use the selectedIndex of the Picker in my ViewController?
Yes, of course! You can fins a lot of examples in that repo. Just clone this repo and open xcworspace
file.
I only found doneBlock: {ActionStringDoneBlock in return}
in your Swift sample code. But there is no example with a "programmed out" block of the doneBlock. I mean how can i write a correct done block in which i set the selected index e.g. self.selectedIndex = selectedIndex
I am getting the same thing. Would be great to have a clear, working example of how to get the value from the picker
@loomtronic is this error exists in example project? Can you point it out? Because I'm confused and have no idea, how to reproduce it.
I haven't tried it in the example project... the example project I have not seen any Swift examples for this code. The Swift examples only have doneBlock: {ActionStringDoneBlock in return}, not the code @manzznam is using
Yes that was my question as well. I only need some sample Swift code how to get the selected Index in that doneBlock.
@manzznam, @loomtronic Yes, you're right! It's a good question, thank you! It's fucking closure syntax! Spend an hour to figure out, how to do it! Check examples now.
Thank you, now it's working. Great job
I alwas get this error when i try to write to the "index" variable in this "done" block. I took the code from the Swift Example. A println works inside the block but access to any variable doesn't.
@IBAction func pickerTouched(sender: UIButton) { var index = 0