Post

Replies

Boosts

Views

Activity

Reply to Mac Catalyst UIActivity subclasses that implement the activityViewController property don't work. API is broken.
I don't think I want to burn a TSI on this since I have a workaround though all the available workarounds using public API are not great. On Catalyst you have to manually dismiss the UIActivity's activityViewController property in -activityDidFinish: since the popover holding the UIActivityViewController immediately dismisses after you click the application activity. Also an extra strong reference to the custom UIActivity is required otherwise it gets released with the UIActivityViewController before it has a chance to finish and the abandoned view controller remains in the UI. Another option is to just not use a popover with UIActivityViewController but that isn't Mac like.
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’22
Reply to Mac Catalyst UIActivity subclasses that implement the activityViewController property don't work. API is broken.
Thanks a lot for the reply. The reason why I invoke -performActivity manually is because I just choose to use this method as the place to "start" the work but it is not at all related to the reported issue. My implementation never calls super and the system does not call -performActivity on an activity that returns an activityViewController. You can rename the -performActivity method in the sample project to any method name you want but the issue will still occur: -(void)_doStartActivityWork {     NSLog(@"start performing...");     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{         [self activityDidFinish:YES];         NSLog(@"Finished performing.");     }); }
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’22
Reply to Mac Catalyst Make Text in UICollectionViewCell configured with UIListContentConfiguration selectable with mouse/trackpad?
None of the options here are particularly good. Going through your suggestions, I tried making a UITextField look like a label (since that suggestion seemed like the easiest way to achieve the behavior I'm after) but I just couldn't get it to work. I had a UITextField looking like a label by setting it to have no border style and an attributed string that wraps words (I need multiline support too). That looked okay, but couldn't figure out how to make the UITextField "selectable" but not "editable." If I set enabled to NO the text field wouldn't be selectable or editable. If I left the UITextField enabled and tried to suppress editing via the delegate methods, a multiline UITextField would then render the string on a single line when it gets focus (snapping a multiline string to 1 line during text selection isn't going to work). Maybe there is a way to do it with UITextField but I couldn't figure it out.... The thought of using UITextViews and making them look like labels was something I wasn't really willing to try since UITextView is pretty heavyweight. I'm sure it's possible but I wasn't going to go down that road. I need like 20 or so of these "labels" in this UI and these are self sizing cells some with "side by side" text and the window is resizable and the thought of trying to dumb down UITextViews to behave like labels was giving me nightmares. A few years ago I tried putting non editable UITextViews in a UITableView with disastrous results. Maybe it's not that hard though. I didn't really feel like trying it. Embedding SwiftUI is not something I'm going to do here. This view controller is in Objective-C and I don't believe you can use UIHostingConfiguration from Objective-C (at least not easily). I'm definitely not trying to throw out the entire view controller, rewriting the whole thing in Swift with the only tangible benefit being text selection. So I ended up dropping down to TextKit and wrote my own. Not really fun having to spend so much on a feature that desktop platforms typically give us for free. I hope Catalyst will add support for selectable labels in the future since it really is a must have for many Desktop apps. Now I just have to hack my way into NSColor.selectedTextBackgroundColor from the Mac Catalyst environment.... I think Catalyst would be a lot more useful if more of the AppKit APIs were exposed so developers could fallback to it when needed. Support for allowing developers to embed AppKit views in a view hierarchy would be nice too. I could have just embedded a NSTextField instead of a UILabel and been on my way.
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’22
Reply to Mac Catalyst Make Text in UICollectionViewCell configured with UIListContentConfiguration selectable with mouse/trackpad?
Yikes, having to throw away my existing cells for such a basic feature is kind of a disappointment and I'm wondering if choosing Mac Catalyst over AppKit was a good choice since I have to roll out a lot of my own stuff to get the behavior you'd expect on a desktop app in many places, and also have to resort to some hacks. I do appreciate your reply though.
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’22
Reply to wkwebview.navigationdelegate is still nil after assigned delegate
What about the WKWebView itself? Is the_wkWebView not being retained? Do you have a strong reference to it? If the wkWebView is not nil you can try subclassing and overriding the navigationDelegate setter and set a breakpoint in it to see if some other code is setting it to nil after you assign it: //In a WKWebView subclass -(void)setNavigationDelegate:(id<WKNavigationDelegate>)navigationDelegate {     [super setNavigationDelegate:navigationDelegate];     if (navigationDelegate == nil)     {         NSLog(@"set a breakpoint here.");     } }
Topic: Programming Languages SubTopic: General Tags:
Nov ’22
Reply to Is StoreKit 2 for Swift only?
Ya I think you'd have to box all the StoreKit2 structs in classes that inherit from NSObject to access it from Objective-C, which would be pretty time consuming. Not sure why they decided to make it so difficult to use this API from an Objective-C app.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Reply to NSUndoManager -setActionName: being ignored on Mac Catalyst
Just to add another note...the system doesn't appear to enumerating through the responder chain in the proper order when validating undo/redo commands. For example if a UITextField has focus/firstResponder status -canPerformAction:withSender: is hitting my responder implementing this workaround first and you could accidentally swallow the UITextField's undo/redos with this workaround if you're not careful... So you also have to check that a text field is first responder/has focus and if it does call through to super so you don't swallow the text field's undo/redo. Not sure why the system doesn't start validating undo/redo starting from the first responder, then enumerate responders backward until undo/redo validates. The system seems to be starting from the UIWindow and digging through the responder chain in the wrong order. Note that calling through to super from -canPerformAction:withSender: when the text field has focus will leave you with an Undo/Redo menu item that doesn't have a proper action name (it should say "Undo Typing"). This can be fixed, if you are determined enough to write even more workaround code to get the proper behavior. This is kind of a nightmare. I'm spending so much time implementing workarounds like this. Not sure if skipping AppKit with this UIKit shortcut is actually saving me anytime at all, but I'm in too deep now though.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’22
Reply to NSUndoManager -setActionName: being ignored on Mac Catalyst
This works around the problem. I'm sharing it with the community because I'm that type of guy: Add the following methods in the responder chain: -(void)redo:(id)sender; -(void)undo:(id)sender; Implement the methods like so: -(void)redo:(id)sender {     NSUndoManager *undoManager = self.undoManager;     [undoManager redo]; } -(void)undo:(id)sender {     NSUndoManager *undoManager = self.undoManager;     [undoManager undo]; } Validate the methods: -(BOOL)canPerformAction:(SEL)action withSender:(id)sender {  if (action == @selector(undo:))     { return self.undoManager.canUndo; } else if (action == @selector(redo:)) { return self.undoManager.canRedo; } return [super canPerformAction:action withSender:sender]; } Then the undo/redo menu items in the menu bar will update with the action name proper. You're welcome.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’22
Reply to Mac Catalyst: UISplitViewControllerColumnSecondary doesn't get key focus when the Tab Key is Pressed in a Triple UISplitViewController.
Thanks a lot for the reply. I filed a feedback with a sample project and screen capture FB11745181. In the sample project I used a plain UIScrollview. Tabbing into it doesn't work. After fiddling with the quick sample I noticed that arrow key scrolling doesn't work at all (even when clicking on the scroll view). In the app I'm actually working on I'm using a WKWebView which does have arrow key scrolling implemented but was requiring at least a mouse click on the web view before it started working (couldn't tab in). It's hard to say what might be happening without a sample project, but — on the Mac — keyboard navigation is going to change first-responder, not focus. That's what I thought. I fiddled with calls to -becomeFirstResponder with no luck (on the view controller and on the web view itself). Subclassing and returning YES from -canBecomeFocused on the view is all I needed to do to get focus to move over with the tab key, without messing with the responder chain at all. But I also needed to implement my own key commands to actually do the scrolling now because the default web view ones don't work after these overrides.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’22
Reply to Mac Catalyst UIActivity subclasses that implement the activityViewController property don't work. API is broken.
I don't think I want to burn a TSI on this since I have a workaround though all the available workarounds using public API are not great. On Catalyst you have to manually dismiss the UIActivity's activityViewController property in -activityDidFinish: since the popover holding the UIActivityViewController immediately dismisses after you click the application activity. Also an extra strong reference to the custom UIActivity is required otherwise it gets released with the UIActivityViewController before it has a chance to finish and the abandoned view controller remains in the UI. Another option is to just not use a popover with UIActivityViewController but that isn't Mac like.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Mac Catalyst UIActivity subclasses that implement the activityViewController property don't work. API is broken.
Thanks a lot for the reply. The reason why I invoke -performActivity manually is because I just choose to use this method as the place to "start" the work but it is not at all related to the reported issue. My implementation never calls super and the system does not call -performActivity on an activity that returns an activityViewController. You can rename the -performActivity method in the sample project to any method name you want but the issue will still occur: -(void)_doStartActivityWork {     NSLog(@"start performing...");     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{         [self activityDidFinish:YES];         NSLog(@"Finished performing.");     }); }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Mac Catalyst Make Text in UICollectionViewCell configured with UIListContentConfiguration selectable with mouse/trackpad?
None of the options here are particularly good. Going through your suggestions, I tried making a UITextField look like a label (since that suggestion seemed like the easiest way to achieve the behavior I'm after) but I just couldn't get it to work. I had a UITextField looking like a label by setting it to have no border style and an attributed string that wraps words (I need multiline support too). That looked okay, but couldn't figure out how to make the UITextField "selectable" but not "editable." If I set enabled to NO the text field wouldn't be selectable or editable. If I left the UITextField enabled and tried to suppress editing via the delegate methods, a multiline UITextField would then render the string on a single line when it gets focus (snapping a multiline string to 1 line during text selection isn't going to work). Maybe there is a way to do it with UITextField but I couldn't figure it out.... The thought of using UITextViews and making them look like labels was something I wasn't really willing to try since UITextView is pretty heavyweight. I'm sure it's possible but I wasn't going to go down that road. I need like 20 or so of these "labels" in this UI and these are self sizing cells some with "side by side" text and the window is resizable and the thought of trying to dumb down UITextViews to behave like labels was giving me nightmares. A few years ago I tried putting non editable UITextViews in a UITableView with disastrous results. Maybe it's not that hard though. I didn't really feel like trying it. Embedding SwiftUI is not something I'm going to do here. This view controller is in Objective-C and I don't believe you can use UIHostingConfiguration from Objective-C (at least not easily). I'm definitely not trying to throw out the entire view controller, rewriting the whole thing in Swift with the only tangible benefit being text selection. So I ended up dropping down to TextKit and wrote my own. Not really fun having to spend so much on a feature that desktop platforms typically give us for free. I hope Catalyst will add support for selectable labels in the future since it really is a must have for many Desktop apps. Now I just have to hack my way into NSColor.selectedTextBackgroundColor from the Mac Catalyst environment.... I think Catalyst would be a lot more useful if more of the AppKit APIs were exposed so developers could fallback to it when needed. Support for allowing developers to embed AppKit views in a view hierarchy would be nice too. I could have just embedded a NSTextField instead of a UILabel and been on my way.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Mac Catalyst Make Text in UICollectionViewCell configured with UIListContentConfiguration selectable with mouse/trackpad?
Yikes, having to throw away my existing cells for such a basic feature is kind of a disappointment and I'm wondering if choosing Mac Catalyst over AppKit was a good choice since I have to roll out a lot of my own stuff to get the behavior you'd expect on a desktop app in many places, and also have to resort to some hacks. I do appreciate your reply though.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to wkwebview.navigationdelegate is still nil after assigned delegate
What about the WKWebView itself? Is the_wkWebView not being retained? Do you have a strong reference to it? If the wkWebView is not nil you can try subclassing and overriding the navigationDelegate setter and set a breakpoint in it to see if some other code is setting it to nil after you assign it: //In a WKWebView subclass -(void)setNavigationDelegate:(id<WKNavigationDelegate>)navigationDelegate {     [super setNavigationDelegate:navigationDelegate];     if (navigationDelegate == nil)     {         NSLog(@"set a breakpoint here.");     } }
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Is StoreKit 2 for Swift only?
Ya I think you'd have to box all the StoreKit2 structs in classes that inherit from NSObject to access it from Objective-C, which would be pretty time consuming. Not sure why they decided to make it so difficult to use this API from an Objective-C app.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to NSUndoManager -setActionName: being ignored on Mac Catalyst
Just to add another note...the system doesn't appear to enumerating through the responder chain in the proper order when validating undo/redo commands. For example if a UITextField has focus/firstResponder status -canPerformAction:withSender: is hitting my responder implementing this workaround first and you could accidentally swallow the UITextField's undo/redos with this workaround if you're not careful... So you also have to check that a text field is first responder/has focus and if it does call through to super so you don't swallow the text field's undo/redo. Not sure why the system doesn't start validating undo/redo starting from the first responder, then enumerate responders backward until undo/redo validates. The system seems to be starting from the UIWindow and digging through the responder chain in the wrong order. Note that calling through to super from -canPerformAction:withSender: when the text field has focus will leave you with an Undo/Redo menu item that doesn't have a proper action name (it should say "Undo Typing"). This can be fixed, if you are determined enough to write even more workaround code to get the proper behavior. This is kind of a nightmare. I'm spending so much time implementing workarounds like this. Not sure if skipping AppKit with this UIKit shortcut is actually saving me anytime at all, but I'm in too deep now though.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to NSUndoManager -setActionName: being ignored on Mac Catalyst
This works around the problem. I'm sharing it with the community because I'm that type of guy: Add the following methods in the responder chain: -(void)redo:(id)sender; -(void)undo:(id)sender; Implement the methods like so: -(void)redo:(id)sender {     NSUndoManager *undoManager = self.undoManager;     [undoManager redo]; } -(void)undo:(id)sender {     NSUndoManager *undoManager = self.undoManager;     [undoManager undo]; } Validate the methods: -(BOOL)canPerformAction:(SEL)action withSender:(id)sender {  if (action == @selector(undo:))     { return self.undoManager.canUndo; } else if (action == @selector(redo:)) { return self.undoManager.canRedo; } return [super canPerformAction:action withSender:sender]; } Then the undo/redo menu items in the menu bar will update with the action name proper. You're welcome.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Mac Catalyst: UISplitViewControllerColumnSecondary doesn't get key focus when the Tab Key is Pressed in a Triple UISplitViewController.
Thanks a lot for the reply. I filed a feedback with a sample project and screen capture FB11745181. In the sample project I used a plain UIScrollview. Tabbing into it doesn't work. After fiddling with the quick sample I noticed that arrow key scrolling doesn't work at all (even when clicking on the scroll view). In the app I'm actually working on I'm using a WKWebView which does have arrow key scrolling implemented but was requiring at least a mouse click on the web view before it started working (couldn't tab in). It's hard to say what might be happening without a sample project, but — on the Mac — keyboard navigation is going to change first-responder, not focus. That's what I thought. I fiddled with calls to -becomeFirstResponder with no luck (on the view controller and on the web view itself). Subclassing and returning YES from -canBecomeFocused on the view is all I needed to do to get focus to move over with the tab key, without messing with the responder chain at all. But I also needed to implement my own key commands to actually do the scrolling now because the default web view ones don't work after these overrides.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’22