Normalized way to access the "real" UIView object within a ui.View?
For...reasons...I need to call the objective-C method:
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.
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
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.
@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.
You may be interested in my objc 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.