Set Picker.Enabled = False

Basically I have an IOS app that uses a Picker. When the Picker is used to select that item of interest I use an API to communicate remotely to a db. I would like to disable the Picker while waiting on the response. I need to disable further Picker movement until a response or time out has occurred.

Is there a way to set Picker.Enabled = False and then when either response received or comm timeout occurs then set Picker.Enabled = True?

I could not find a way to do this for IOS Picker in a similar manner as I would for Desktop or Web PopUpMenu so I created another View that is populated after the PickerSelection has been made.

are you setting the isEnabled or UserInteraction property?

I am using Extensions.PickerView and neither isEnabled or UserInteraction property are visible

Try:

[code]Declare sub setUserInteration lib UIKitLib selector “setUserInteractionEnabled:” (obj_id as ptr, en as Boolean)

SetUserInteraction(myPicker.Handle, false)[/code]

To re-enable call it again with true

@Jason King Very Cool and Thank you. At first this errored then I used ‘selector’ as keyword to search and found examples in the UIKit. Then I made slight syntax update and all is good .

Declare sub setUserInteraction lib "UIKit.framework" selector "setUserInteractionEnabled:" (obj_id as ptr, en as Boolean) setUserInteraction(myPicker.Handle, false)

If I missed documentation on this my bad but if not this is hugely valuable.

This is extending the ask. I looked through the UIKit on how to lock rotation to Portrait or Landscape then enable rotation. My thoughts are if I could find the correct selector I may have a solution. How close am I?

Unfortunately locking rotation for a specific view isn’t as easy as writing a declare.
You actually need to override a property/method at system level.

This would be the Swift code:

[code]override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.all //return the value as per the required orientation
}

override var shouldAutorotate: Bool {
return false
}[/code]
Source: https://stackoverflow.com/questions/43795577/how-to-lock-orientation-for-iphone-for-certain-view-controllers-swift

But maybe Jason knows how to do this, I would be very interested !

I had that working at one point I believe. I’ll try and dig through my laptop on Friday.

I can’t seem to find it and fear it was on my old laptop that died a few years back. I know that it can be done using method swizzling like I did for the ImprovediOSApplication class since getters in objective-c are still just functions that can be overridden. If that project doesn’t provide enough info to get to the bottom of this please let me know and I can try to help but I’m not going to have the time to test this for a couple months.

To get the values of constants you can use a Swift playground. Make a new playground and type:

[code]import UIKit

var test = UIInterfaceOrientationMask.All.rawValue[/code]
And you will see that the value of that constant is 30. You can do the same with all the others and find they are:

Landscape = 24 LandscapeLeft = 16 LandscapeRight = 8 Portrait = 2 PortraitUpsideDown = 4 All = 30 AllButUpsideDown = 26

“a few years back” those functions where “functions” today they are “computed properties” as denoted by the “var”
I don’t recall which iOS version changed that … but they went from “func” to “var” … so what you had working in the past probably wouldn’t work today.

Also… as a side note… not all those orientations work on the “X” models of iPhones

It changed for just this property? in Objective C too? Or just swift? Because all properties that my declares access are using functions so I’m pretty sure it will still work. I definitely believe that the way swift does it could have changed, but since Objective C is still supported and now declares need to work I think we should be ok.

No… there were a few that changed… and I wouldn’t think Apple would change it for just Swift or just ObjC since both are tied to the same framework

and based on what I see in Apples docs… both ObjC and Swift use “similar” syntax for these

I know for sure that

  • prefersStatusBarHidden
  • preferredStatusBarStyle
  • supportedInterfaceOrientations
  • shouldAutorotate

all changed… probably in iOS9 (but I’m guessing)

Any news @Jason King ?

Unfortunately I couldn’t find it. See above:

[quote=432557:@Jason King]To get the values of constants you can use a Swift playground. Make a new playground and type:

[code]import UIKit

var test = UIInterfaceOrientationMask.All.rawValue[/code]
And you will see that the value of that constant is 30. You can do the same with all the others and find they are:

Landscape = 24 LandscapeLeft = 16 LandscapeRight = 8 Portrait = 2 PortraitUpsideDown = 4 All = 30 AllButUpsideDown = 26[/quote]

Sorry Jason, I missed that message.

No worries. If you don’t get it figured out my mid July I should be able to tackle it then. You’ll have to remind me though