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

1 Like

ā€œ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