Set Picker.Enabled = False

  1. 4 months ago

    Carl F

    Apr 4 Pre-Release Testers, Xojo Pro Webster, NY USA

    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?

    Try:

    Declare sub setUserInteration lib UIKitLib selector “setUserInteractionEnabled:” (obj_id as ptr, en as Boolean)
    
    SetUserInteraction(myPicker.Handle, false)

    To re-enable call it again with true

  2. 3 months ago

    Carl F

    Apr 9 Pre-Release Testers, Xojo Pro Webster, NY USA

    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.

  3. Dave S

    Apr 9 San Diego, California USA

    are you setting the isEnabled or UserInteraction property?

  4. Carl F

    Apr 9 Pre-Release Testers, Xojo Pro Webster, NY USA

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

  5. Jason K

    Apr 9 Pre-Release Testers Answer

    Try:

    Declare sub setUserInteration lib UIKitLib selector “setUserInteractionEnabled:” (obj_id as ptr, en as Boolean)
    
    SetUserInteraction(myPicker.Handle, false)

    To re-enable call it again with true

  6. Carl F

    Apr 10 Pre-Release Testers, Xojo Pro Webster, NY USA

    @Jason K 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.

  7. Carl F

    Apr 10 Pre-Release Testers, Xojo Pro Webster, NY USA

    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?

  8. Jeremie L

    Apr 10 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io
    Edited 3 months ago

    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:

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
            return UIInterfaceOrientationMask.all //return the value as per the required orientation 
        }
    
    override var shouldAutorotate: Bool {
            return false
        }

    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 !

  9. Jason K

    Apr 10 Pre-Release Testers

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

  10. Jason K

    Apr 12 Pre-Release Testers

    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.

  11. Jason K

    Apr 12 Pre-Release Testers

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

    import UIKit
    
    var test = UIInterfaceOrientationMask.All.rawValue

    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
  12. Dave S

    Apr 12 San Diego, California USA

    @Jason K I can't seem to find it and fear it was on my old laptop that died a few years back.

    "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

  13. Jason K

    Apr 12 Pre-Release Testers

    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.

  14. Dave S

    Apr 12 San Diego, California USA
    Edited 3 months ago

    @Jason K It changed for just this property? in Objective C too? Or just swift?

    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)

  15. Jeremie L

    Apr 18 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io
    Edited 3 months ago

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

    Any news @Jason K ?

  16. Jason K

    Apr 18 Pre-Release Testers

    @Jeremie L Any news @Jason K ?

    Unfortunately I couldn’t find it. See above:

    @Jason K 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.

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

    import UIKit
    
    var test = UIInterfaceOrientationMask.All.rawValue

    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

  17. Jeremie L

    Apr 18 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io

    Sorry Jason, I missed that message.

  18. Jason K

    Apr 18 Pre-Release Testers

    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

or Sign Up to reply!