omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Normalized way to access the "real" UIView object within a ui.View?

    Pythonista
    objcutil ui.view
    3
    4
    2737
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shinyformica
      shinyformica last edited by

      For...reasons...I need to call the objective-C method:

      addTarget_action_forControlEvents_()

      on all the controls within a ui.View in my UI...but as I'm now aware, the actual object we get from ObjCInstance(view) or the view.objc_instance property is some SUIView object, like SUIButton or SUISlider, and the way to get down to the "real" UIControl or UIView object seems to vary from control to control...for a ui.Button, I can do:

      realbutton = button.objc_instance.button()

      but for a ui.Switch it's:

      realswitch = switch.objc_instance.switchControl()

      and for a ui.TextField it's:

      realtextfield = textfield.objc_instance.textField()

      and I found that for some, like ui.ImageView, there doesn't appear to be an obvious way to access the real UIView object...or there is, and I haven't found it...is there some more standardized way to access the underlying actual UIControl instance inside the Pythonista-wrapped controls? I can definitely map from each control type to the necessary access method, but that would have to be done per-control, and I'd prefer a generalized method.

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        There isn't a "standardized" way to do this, mostly because there isn't a one-to-one mapping between UIKit views and classes in the ui module.

        I guess you could just walk the view hierarchy until you find a view of the type (e.g. UISwitch) you're interested in though.

        1 Reply Last reply Reply Quote 0
        • shinyformica
          shinyformica last edited by

          @omz thanks for the reply!

          Seems to be the case with ui.Button, though in that case I only see the hidden UIButton subview by looking at button.objc_instance.subviews(). Same for ui.Switch and ui.Textfield. But not for ui.Slider, for example. Anyway, looking at the subviews does give me a way to get at it for a couple views I otherwise was having trouble with.

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            You may be interested in my objc viewbrowser:
            https://github.com/jsbain/viewbrowser

            You can present your view, then traverse the heirarchy to see all of the UIViews. Tapping an item highlights it onscreen.
            Also, any action/targets are shown as little chain icons, which you can tap and it prints to the console the details on the target, selector, event codes, etc. Tapping the info button shows all of the objc properties, which is also navigatable.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post
            Powered by NodeBB Forums | Contributors