Date
1 - 4 of 4
Difference in View Identifiers between Mac and iOS?
Dave
Hi,
I’m moving some IB Views Across from iOS to Mac. By moving, I mean re-creating as you can’t copy+paste between iOS and Mac Storyboards. In the IOS Storyboard view controller, I have some Views that need the Identifier set (e.g. [myView identifier]), when I look at he Class panel of these views, I see two identifier fields, one at the top in the “Identity” Panel with a “Restoration ID” field and one further down in the “Accessibility” Panel, “Identifier”. I set the Accessibility Identifier in this case and it results in the ID appearing in the “identifier” property of the View. On Mac there is an “Identity” Panel with an “Identifier” field and further down an “Accessibility Identifier” Panel with another “Identifier” field. Which of these two fields should I be using to have it appear in the “identifier” property of the View? I have some common code that expects the view.identifier to be set correctly. Thanks a lot All the Best Dave |
|
Fritz Anderson
On 27 Aug 2017, at 6:44 AM, Dave <dave@...> wrote:
I’m moving some IB Views Across from iOS to Mac. By moving, I mean re-creating as you can’t copy+paste between iOS and Mac Storyboards.Makes sense. NIBs contain freeze-dried instances of the objects themselves. UIView and NSView have no ancestors in common below NSObject. In the IOS Storyboard view controller, I have some Views that need the Identifier set (e.g. [myView identifier]), when I look at he Class panel of these views, I see two identifier fields, one at the top in the “Identity” Panel with a “Restoration ID” field and one further down in the “Accessibility” Panel, “Identifier”. --- # What identifier? Your mention of an `.identifier` property confuses me. Doc searches are always hit-or-miss, but it seems UIView has no property of exactly that name. I can’t see how your common code can expect a correct “identifier” when none exists. Both have an `.accessibilityIdentifier`, but I believe it’s guaranteed unique only if fully-qualified by the IDs in its containment hierarchy, which may include indices. If your setup permits unique leaf identifiers this wouldn’t be a problem. Both have view-restoration IDs, but with different names, `.identifier` for NSView, `.restorationIdentifier` for UIView. --- # In Interface Builder That’s the state of play when you get to the IB Identity inspector. ## UIView Identity/Restoration ID, used for view restoration {→ UIView.restorationIdentifier). Accessibility/Identifier, for access to the view in accessibility and automated testing (→ UIAccessibilityIdentification.accessibilityIdentifier). ## NSView Identity/Identifier, used for window/view restoration (→ NSUserInterfaceItemIdentification.identifier). Accessibility Identity/Identifier, again for accessibility (→ NSAccessibilityElementProtocol.accessibilityIdentifier). ## IB-only IB has Document/Label everywhere so you can keep everything straight in the detail list and labels for constraints. --- # Weird thing about accessibilityIdentifier My archaeology says that accessibilityIdentifier was first exposed in iOS 8 retroactive to iOS 5. That may explain why some of the guides don’t illustrate the field. It’s apparently immemorial in OS X. |
|
Gary L. Wade
That will be possible under the Apple Grand Unified Understandable Design (Apple GUUD).
toggle quoted message
Show quoted text
Just kidding…or maybe not! Tangentially speaking, if you need to do this a lot, you could (besides writing a radar) write an app whose only purpose is to read in the pasteboard, and if you encounter NSView objects, it would add a version comparable for iOS. I've not done this in particular, but I'd guess the objects are just key-coding encoded, and you wouldn't necessarily need to instantiate them, just create versions that match all the changes you need. There's a sample app somewhere on Apple's site that allows you to inspect all the pasteboards. Plus, if you feel really lucky, play with the contents of the storyboards in BBEdit. -- Gary L. Wade http://www.garywade.com/ On Aug 27, 2017, at 4:44 AM, Dave <dave@...> wrote: |
|
Dave
Hi,
On iOS: UIView myView; myID = myView.accessibilityIdentifier; In code gets the identifier specified in the “Identifier” Field in the Accessibility Panel of the Storyboard/NIB. On Mac: NSView myView; myID = myView.accessibilityIdentifier; Returns nil even if the “ Identifier” Field in the Accessibility Identity Panel is set. In this case, doing: myWorkID = myView.identifier; Returns _NS:44 (or whatever), but if I change the Storyboard/NIB to set the “identifier” field in the “Identity" Panel, then this works as per the “accessibilityIdentifier” on iOS. My main question is why all the different identifiers? I can make it work now, but why can’t I set/use “accessibilityIdentifier” on the Mac? All the Best Dave |
|