Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics

Post

Replies

Boosts

Views

Activity

Print a SwiftUI view on macOS?
I made a test with a new XIB-based project using this code     func applicationDidFinishLaunching(_ aNotification: Notification) {         guard let content = window.contentView else {             print("Error: cannot access windows contentview!")             return         }                  let tv = NSTextView(frame: NSMakeRect(100, 300, 200, 40))         tv.string = "Text subview"         tv.font = NSFont.systemFont(ofSize: 30.0)         content.addSubview(tv)         let chartView = NSHostingView(rootView: myChart())         chartView.setFrameSize(content.frame.size)         content.addSubview(chartView)         content.printView(self)             } "myChart" is s sample view using Charts. The window does show the text and the chart but the print shows the text only. How can I get the SwiftUI-View printed? My goal is a PDF output of a SwiftUI view. There are already several older threads with similar questions but no solution, yet.
2
0
715
Dec ’22
NavigationStack inside NavigationSplitView on Mac
I've seen several posts regarding NavigationStack in a NavigationSplitView. All had specific issues and some were marked as resolved. I couldn't get any of the suggested solutions working on macOS so I'll present some stripped down examples, all part of FB11842563: 1. Sidebar Selection struct SidebarSelection: View {     @State var selection: Int?     @State var path: [Int] = []     var body: some View {         NavigationSplitView {             List(1...20, id: \.self, selection: $selection) { number in                     Text("I like \(number)")             }         } detail: {             NavigationStack(path: $path) {                 VStack {                     Image(systemName: "x.squareroot")                         .imageScale(.large)                         .foregroundColor(.accentColor)                     Text("This is the NavigationStack root")                 }                 .padding()                 .navigationDestination(for: Int.self) { number in                     Text("You chose \(number)")                 }             }         }         .onChange(of: selection) { newValue in             print("You clicked \(newValue)")             if let newValue {                 path.append(newValue)             }         }         .onChange(of: path) { newValue in             print("Path changed to \(path)")         }     } } If we run this and click: „I like 5“ „I like 6“ „I like 7“ We would expect the detail view to show: „You chose 5“ „You chose 6“ „You chose 7“ And the console to show: You clicked Optional(5) Path changed to [5] You clicked Optional(6) Path changed to [5, 6] You clicked Optional(7) Path changed to [5, 6, 7] What we actually see in the detail view is: „You chose 5“ „This is the NavigationStack root“ „You chose 7“ And the console shows: Update NavigationRequestObserver tried to update multiple times per frame. You clicked Optional(5) Path changed to [5] You clicked Optional(6) Path changed to [] You clicked Optional(7) Path changed to [7] 2. Sidebar and Stack Selection Now we copy the list to the navigationDestination: struct SidebarAndStackSelection: View {     @State var selection: Int?     @State var path: [Int] = []     var body: some View {         NavigationSplitView {             List(1...20, id: \.self, selection: $selection) { number in                     Text("I like \(number)")             }         } detail: {             NavigationStack(path: $path) {                 VStack {                     Image(systemName: "x.squareroot")                         .imageScale(.large)                         .foregroundColor(.accentColor)                     Text("This is the NavigationStack root")                 }                 .padding()                 .navigationDestination(for: Int.self) { number in                     VStack {                         Text("You chose \(number)")                         List(1...20, id: \.self, selection: $selection) { number in                             Text("I like \(number)")                         }                     }                 }             }         }         .onChange(of: selection) { newValue in             print("You clicked \(newValue)")             if let newValue {                 path.append(newValue)             }         }         .onChange(of: path) { newValue in             print("Path changed to \(path)")         }     } } We repeat our test from above, clicking either on the sidebar or in the detail view and we expect the same outcome. This time the detail view shows the expected screen and the path is not completely wiped out but it is also not appended: Update NavigationRequestObserver tried to update multiple times per frame. You clicked Optional(5) Path changed to [5] You clicked Optional(6) Path changed to [6] You clicked Optional(7) Path changed to [7] 3. Sidebar and Stack Selection, initialized Same as before, but now we initialize the view with a non-empty path: SidebarAndStackSelection(path: [1]) The app freezes on launch, CPU is at 100 percent and the console shows only: Update NavigationRequestObserver tried to update multiple times per frame. Update NavigationRequestObserver tried to update multiple times per frame. The SwiftUI instruments seem to show heavy activity of the Stack and the SplitView: 4. Selection only in Stack Once we remove the selection from the sidebar everything works as expected (adding the NavigationStack to the root view to be able to click on a number): struct SidebarWithoutSelectionButStack: View {          @State var selection: Int?     @State var path: [Int] = []          var body: some View {         NavigationSplitView {             List(1...20, id: \.self) { number in                     Text("I like \(number)")             }         } detail: {             NavigationStack(path: $path) {                 List(1...20, id: \.self, selection: $selection) { number in                     Text("I like \(number)")                 }                 .padding()                 .navigationDestination(for: Int.self) { number in                     VStack {                         Text("You chose \(number)")                         List(1...20, id: \.self, selection: $selection) { number in                             Text("I like \(number)")                         }                     }                 }             }         }         .onChange(of: selection) { newValue in             print("You clicked \(newValue)")             if let newValue {                 path.append(newValue)             }         }         .onChange(of: path) { newValue in             print("Path changed to \(path)")         }     } } Problem of course is, that now the sidebar is useless.
6
2
1.7k
Dec ’22
SwiftU keyboard toolbar disappearing after present additional .sheet
I added a keyboard toolbar inside ZStack. And it works right after appears as expected But after opening and closing another view over the .sheet modifier, The keyboard toolbar doesn't show anymore. ZStack { . .. TextField() .toolbar { ToolbarItemGroup(placement: .keyboard) { .... } } } .sheet(isPresent: $binding) { Some other view } Seems it happened after upgrading to iOS 16. Does anybody has the solution? Thanks
8
5
3.3k
Dec ’22
Localization settings hidden if only 1 preffered language in iOS
I have added additional localizations into my iOS app. iOS is not available in those languages. So I did as it is suggested that you redirect customers to app settings view UIApplication.openSettingsURLString and there they can select another app language. Unfortunately they do not see language selection if they do not have set at least 2 Preferred languages in General -> Languages & Region. Also it does not matter what languages they have there. If my app does not support those then it still shows all localizations available. Is there somehow to force it? So it would be visible always? Since most people in my country have iPhones only in English but would like to use Apps in their native language.. Since they do not have 2 preferred languages they cant see the selection :(
7
7
3.8k
Dec ’22
How do I enable UILargeContentViewerInteraction on UITabBar outside of UITabBarController?
UILargeContentViewerInteraction, added in iOS 13, works out of the box on the tab bar in a UITabBarController, and it's easy to set up on a custom view using the UILargeContentViewerItem properties on UIView. But how do I set it up on a UITabBar that's not connected to a UITabBarController? There don't appear to be any relevant properties on UITabBarItem. To try this, I made a sample app, added a tab bar, set up some items, set their largeContentSizeImage properties for good measure, ran the app, set text size to a large accessibility value, and long-pressed on the items, and I get no large content viewer. I also tried adding a UILargeContentViewerInteraction to the tab bar, and implemented the viewControllerForInteraction method in the delegate.
3
1
1k
Dec ’22
setTitleColor not working for UIButton plain style
If I create a Plain style UIButton using the Storyboard, calling the function setTitleColor(_ color: UIColor?, for state: UIControl.State) stop working, or works in a limited way. However, the color of the title can still be modified using its titleLabel?.tintColor property. If I turn UIButton to be Default style, then setTitleColor(_ color: UIColor?, for state: UIControl.State) works as expected. Thank you Mauro Bianchelli.
2
1
1.7k
Dec ’22
Having Trouble passing a ButtonStyle as a parameter to a func
I have a SwiftUI View where the body looks like this              VStack {                   VStack(spacing: 4) {                     Text("Outline")                     Button("Tap Me") {                       print("tapped")                     }                     .buttonStyle(.outline)                   }                   VStack(spacing: 4) {                     Text("Simple")                     Button("Tap Me") {                       print("tapped")                     }                     .buttonStyle(.simple)                   }                 } So to remove the duplication, I want to do something like this:      func textButton(title: String, buttonStyle: ButtonStyle) -> some View {       VStack {         Text(title)         Button("hello") {           print("tapped")         }           .buttonStyle(buttonStyle)       }     } The compiler asks me to add 'any' before ButtonStyle. When I do that I get the following: "Type 'any View' cannot conform to 'View'" It works fine if I don't pass in the ButtonStyle. Any suggestions on how to pass a ButtonStyle into a func? thanks, in advance!
2
1
1.9k
Dec ’22
Its time for SwiftUI on the web! (WASM, WEBGL)
Hello Apple Community, With a backend development background, I was always reluctant to do any front end. Especially with my bad experience with html & css, my negative opinion towards UI only got stronger. When starting a new project at my current company, I was forced to do SwiftUI for iOS. After a few small (I mean really small) hiccups, I really understood the concept and it all became natural. This positive experience made me want to try other front end frameworks which work for web. I dipped my toes into Jetpack Compose, C# UWP/WPF, Rust with EGUI. I was really impressed with the performance and possibilities of Rust (EGUI) compiled to WASM. I was especially impressed that you do not have to use any HTML or CSS rather the rendering is completely up to you just like with a desktop application. I was always disappointed of the necessity of html, but with the rise of WASM in the recent years, I really hope there will be amazing alternatives using WASM & WEBGL. Rust with EGUI is good and all but lets be honest to our self: With the ease of SwiftUI, its obvious why all the best looking applications are on iOS. Its time for SwiftUI in web. The advantages for the developers are obvious: Arguably better UI Framework No Html DOM stuff Friendlier for new developers One framework & language for multiple platforms etc ... But whats in for Apple? Why "waste" resources? In my opinion the most important thing is: Increased Developer adoption What is your opinion on this topic? Would you use SwiftUI for web? What are you currently using for web? Do you prefer any other frontend framework over SwiftUI? (not considering the platform)
3
8
2.2k
Dec ’22
Animation on list not working on NavigationSplitView's `Sidebar`
Here are the sample codes: import SwiftUI struct Item: Identifiable, Hashable { var id = UUID() var text: String } struct Player: Identifiable { var id = UUID() var score: String } struct TestView: View { @State var sidebarItems: [Item] = [ .init(text: "1"), .init(text: "2") ] @State var players: [Player] = [ .init(score: "2"), .init(score: "3"), .init(score: "6"), .init(score: "1")] @State private var selectedItem: Item? var body: some View { NavigationSplitView(columnVisibility: .constant(.all)) { List(sidebarItems, selection: $selectedItem) { item in Text(item.text) } Button("shuffle") { withAnimation(.easeIn) { players.shuffle() sidebarItems.shuffle() } } } content: { List { ForEach(players) { player in Text(player.score) } } } detail: { Text("Detail") } } } struct TestView_Previews: PreviewProvider { static var previews: some View { TestView() } } But as a result. Animation working fine on content but not on sidebar
2
1
642
Dec ’22
SwiftUI StateObject crash: “failed to demangle witness for associated type 'Property’”
Hello, we have weird crash in our app that mostly seems to happen right after launch. It is quite rare and so far I haven’t been able to reproduce it (the info below comes from Crashlytics). The main error message I have is this: failed to demangle witness for associated type 'Property' in conformance 'SwiftUI.StateObject<AppBlock.QuickBlockActivityViewModel>.(unknown context at $18f34e5b8).Box: DynamicPropertyBox' from mangled name ' � ��yxG' - subject type x does not conform to protocol ObservableObject And here is the stack trace: Crashed: com.apple.main-thread 0 libsystem_kernel.dylib 0x7200 __pthread_kill + 8 1 libsystem_pthread.dylib 0x71ac pthread_kill + 268 2 libsystem_c.dylib 0x20ca0 abort + 180 3 libswiftCore.dylib 0x3d7304 swift::fatalError(unsigned int, char const*, ...) + 134 4 libswiftCore.dylib 0x3d7324 swift::warningv(unsigned int, char const*, char*) + 30 5 libswiftCore.dylib 0x3ee678 swift_getAssociatedConformanceWitnessSlowImpl(swift::TargetWitnessTable<swift::InProcess>*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolRequirement<swift::InProcess> const*, swift::TargetProtocolRequirement<swift::InProcess> const*) + 2078 6 libswiftCore.dylib 0x3ecb9c swift_getAssociatedTypeWitness + 236 7 SwiftUI 0x5b838 OUTLINED_FUNCTION_49 + 640 8 SwiftUI 0xa8d68 OUTLINED_FUNCTION_513 + 16260 9 SwiftUI 0x58244 OUTLINED_FUNCTION_177 + 10892 10 SwiftUI 0x95524 OUTLINED_FUNCTION_1160 + 6632 We are using the view model (QuickBlockActivityViewModel) in a SwiftUI view that is part of collection view using the new UIHostingConfiguration from iOS 16. Our view model is a subclass of view model for older iOS versions that conforms to ObservableObject and is marked as @MainActor. And the view model is used like this: @StateObject private var viewModel = QuickBlockActivityViewModel() Internally the view model uses Combine to monitor a couple of states from other parts of the app to modify its properties.
5
2
2k
Jan ’23
iOS SwiftUI WidgetKit: My widgets don’t show up in the ‘Add Widgets’ section
I developed an app with 10 widgets but some iPhone, iPad or macOS users report that my widgets or the "App Name" don't appear in the widgets list when they tried to add the widgets of my app. There's no way I can replicate the problem, but the number of the users that report this issue is growing up every day. It’s not clear if the problem is caused by the iPhone model, a crash on the widget preview or other factors. My widgets previews are built reading static data, so this data is the same in every conditions. I suggest my users to do the following steps: Start the app and go to check again if "App name" appears among widget List Close every app and restart the device; then start the app and go to check again if "App name" appears among widget List Temporarily change system language and turn on Bold Text and go to check again if "App Name" appears among widget List Uninstall and reinstall the app, start the app and go to check again if "App Name" appears among widget List But all users who have tried these steps say that the app still does not appear in the list of widgets. The following code is the one I use inside the main widgets swift file called TodayWidgetExtension: import WidgetKit import SwiftUI struct PlaceholderView : View { var body: some View { Text("loading") } } //MARK: - Main widget bundle configuration @main struct WidgetBundle: WidgetBundle { @WidgetBundleBuilder var body: some Widget { //MARK: - 1 Widget1Large() Widget1Medium() Widget1Small() if #available(iOSApplicationExtension 16.0, *) { Widget1Accessory() } //MARK: - 2 Widget2Large() //MARK: - 3 #if !targetEnvironment(macCatalyst) Widget3Medium() #endif //MARK: - 4 Widget4Large() //MARK: - 5 Widget5Medium() //MARK: - 6 Widget6Large() Widget6Medium() } } struct todaywidgetextension_Previews: PreviewProvider { static var previews: some View { PlaceholderView() .previewContext(WidgetPreviewContext(family: .systemSmall)) } } The only thing that I've noticed debugging the widgets extension is that, even if I don't add any of them to my iPhone screen, Xcode tells me that widgets occupied 20mb of memory (the limit for widgets is 30mb). I tried removing all the widgets from the above code leaving only one (Widget1Small for example), but Xcode continues to tell me that 20mb of memory are still occupied. I hope that someone can help me. Thank you.
1
0
748
Jan ’23
Text view with .timer style expands too much in Live Activity
I'm implementing a Timer in my app and I want the countdown to show up as a Live Activity. It works, but I get a very weird expanding effect on the Text view. The screenshots below show the issue, I can't tell if it's a bug or if I'm doing something wrong. My goal is to shrink the live activity black area so that it's a smaller, more reasonable size. There's no reason for it to be as large as it is on the trailing side. The Live Activity code (very basic):   } dynamicIsland: { context in        } compactTrailing: { // Important bit is here            Text(Date(), style: .timer)        }    } Which renders like this, with a lot of space after the timer: Adding a background color shows the view is expanding: Text(Date(), style: .timer)     .background(.red) And if I replace the timer with a standard text view, then no issue: Text("Hello")        .background(.red) Getting out of live activities and showing a standard timer view, there is no expansion issue: struct TestView: View {     var body: some View {         Text(Date(), style: .timer)             .background(.red)     } } So... I'm stumped. Any advice is appreciated.
6
8
2.9k
Jan ’23
NSTextField changes its text color when users click on it under dark theme
// //  AppDelegate.swift //  HelloCocoa // import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate {     func applicationDidFinishLaunching(_ aNotification: Notification) {                  let myAlert = NSAlert()         myAlert.messageText = "Alert Title"         let messageAttributedString = NSAttributedString(string: "Hello,world", attributes: [.font : NSFont.systemFont(ofSize: 12, weight: .bold)])         let myTextField = NSTextField(labelWithAttributedString: messageAttributedString)         myTextField.allowsEditingTextAttributes = true         myTextField.isSelectable = true         myAlert.accessoryView = myTextField         myAlert.runModal()     }     func applicationWillTerminate(_ aNotification: Notification) {         // Insert code here to tear down your application     }     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {         return true     } } The alert appears like this: but when I clicks on the textfield, the text's color become black: Adding foregroundColor key to attribute dictionary works for me but I really want to know why NSTextfield has such behavior
1
1
850
Jan ’23
Hand tracking to fbx
i saw there is a way to track hands with vision, but is there also a way to record that movement and export it to fbx? Oh and is there a way to set only one hand to be recorded or both at the same time? Implementation will be in SwiftUI
1
0
1.1k
Jan ’23
SwiftUI Navigation Bar appears behind Status Bar
We have a NavigationView embedded within a TabView, like this: TabView(selection: $tabSelection) { NavigationView { When a view gets pushed onto the stack in the NavigationView, the NavigationBar appears too high, almost under the StatusBar, as shown in the attached picture. If you touch the StatusBar, somehow it alerts the NavigationBar to scoot downward into its correct position. I discovered a hack where I quickly toggle the StatusBar off, then back on, which accomplishes the same thing. My question, though, is why is this necessary? Why isn't the NavigationBar in the correct place to begin with? Here's the hack that fixes it: .onAppear { withAnimation(.linear(duration: 0.3)) { appViewModel.hideStatusBar.toggle() } DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { withAnimation(.easeInOut(duration: 0.3)) { appViewModel.hideStatusBar.toggle() } } }
2
0
899
Jan ’23
Crash in [UIViewController _presentViewController:withAnimationController:completion:]
Our app has a Crash, here is the Crash report. How should I investigate this error? Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x9e48 __exceptionPreprocess 1 libobjc.A.dylib 0x178d8 objc_exception_throw 2 UIKitCore 0x326cbc -[UIViewController _presentViewController:withAnimationController:completion:] 3 UIKitCore 0x325c10 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke 4 UIKitCore 0x349598 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] 5 UIKitCore 0x2b7a48 -[_UIViewControllerTransitionContext _runAlongsideCompletions] 6 UIKitCore 0x2b6ad8 -[_UIViewControllerTransitionContext completeTransition:] 7 UIKitCore 0x2b7c38 -[UITransitionView notifyDidCompleteTransition:] 8 UIKitCore 0x2b7838 -[UITransitionView _didCompleteTransition:] 9 UIKit 0xa7e58 -[UITransitionViewAccessibility _didCompleteTransition:] 10 UIKitCore 0x103d464 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ 11 UIKitCore 0xd14ac -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] 12 UIKitCore 0xd0408 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] 13 UIKitCore 0xcfb28 -[UIViewAnimationState animationDidStop:finished:] 14 UIKit 0xb0f50 -[UIViewAnimationStateAccessibility animationDidStop:finished:] 15 UIKitCore 0xcfc3c -[UIViewAnimationState animationDidStop:finished:] 16 UIKit 0xb0f50 -[UIViewAnimationStateAccessibility animationDidStop:finished:] 17 QuartzCore 0x1310c CA::Layer::run_animation_callbacks(void*) 18 libdispatch.dylib 0x3fdc _dispatch_client_callout 19 libdispatch.dylib 0x127f4 _dispatch_main_queue_drain 20 libdispatch.dylib 0x12444 _dispatch_main_queue_callback_4CF 21 CoreFoundation 0x9a6d8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ 22 CoreFoundation 0x7c03c __CFRunLoopRun 23 CoreFoundation 0x80ec0 CFRunLoopRunSpecific 24 GraphicsServices 0x1368 GSEventRunModal 25 UIKitCore 0x3a186c -[UIApplication _run] 26 UIKitCore 0x3a14d0 UIApplicationMain 27 Authenticator 0x9334 main + 26 (AppDelegate.swift:26) 28 ??? 0x1b65de960 (シンボルが不足しています)
4
2
1.2k
Jan ’23
A VZMacGraphicsDisplayConfiguration with a large resolution causes macOS Ventura to incorrectly draw its menu bar items.
Filed as rdar://FB11975037 When macOS Ventura is run as a guest OS within the virtualization framework, the main menu bar items will not be displayed correctly if VZMacGraphicsDisplayConfiguration defines a large resolution. The menu bar titles appear to be using the same color as the menu bar itself. When the Appearance is set to Light, the menu bar items are effectively invisible. When the Appearance is set to Dark, the menu bar items are drawn in what looks like a disabled state. This only affects the menu bar item titles on the left-hand side. The date-time and menu bar icons on the right side are always displayed in the correct color. This appears to be a regression in macOS Ventura as this issue is not present in macOS 12 running as a guest. This bug can be easily reproduced using Apple's own Virtualization sample code titled: "Running macOS in a Virtual Machine on Apple Silicon Macs" Steps to reproduce: Follow the sample code instructions for building and installing a VM.bundle. Before running 'macOSVirtualMachineSampleApp', change the VZMacGraphicsDisplayConfiguration to use: width = 5120, height = 2880, ppi = 144. Run 'macOSVirtualMachineSampleApp' and notice that the menu bar titles on the left side of the screen are not correctly drawn in the guest instance. This has been tested on: Host: macOS 13.1 Guest: macOS 13.x (All versions) Hardware: MBP 14" M1 Pro 32GB/2TB Is there anything that can be done to resolve this issue?
4
2
1.4k
Jan ’23
SwiftUI app crashes while scrolling section in List via ScrollViewReader
In our SwiftUI application , we are using List in one of our screen. We have a requirement to scroll to specific section header. Below code works fine till iOS16 and from iOS16 onwards we are getting the app crash. Can anyone suggest me any probable solution to achive this ?.         ScrollViewReader { proxy in             List {                 ForEach(Array(viewModel.newSections), id: .self) { sectionName in                     Section(header: VStack { LeaguesScheduleListSectionView(text: sectionName) }) {                         ForEach(viewModel.newRowsPerSection[sectionName] ?? []) { leagueScheduleEvent in                             LeaguesScheduleListRowView(leagueSchedule: leagueScheduleEvent)                         }                     }                     .id(sectionName)                 }             }             .listStyle(.plain)             .onAppear(perform: {                  if viewModel.newSections.contains("Today/Ongoing"),                  viewModel.newRowsPerSection[("Today/Ongoing")]?.count ?? 0 > 0 {                  proxy.scrollTo("Today/Ongoing", anchor: UnitPoint.topLeading)                  }             })         }
2
0
952
Mar ’23
SwiftUI’s LongPressGesture is broken
Problem LongPressGesture ignores minimumDuration parameter and succeeds immediately, also onEnded is never invoked. Steps to reproduce Take Apple’s own sample code from their documentation: LongPressGesture. Remove transaction.animation = Animation.easeIn(duration: 2.0) line to make the effect more obvious. Expected result: The circle must turn red after 3 seconds of pressing on it, and turn green when released. Actual result The circle turns red immediately and never turns green. Notes I tried many combinations of .gesture and .simultaneousGesture applied to different types of views. Was anyone able to make the minimum duration work when passed to .gesture modifier?
3
4
829
Mar ’23
UIDeferredMenuElement With Uncached Provider Not Working on Mac Catalyst. Uncached provider block never called and menu displays as "Loading"
I'm trying to create a dynamic menu on Mac Catalyst. Using a UIBarButtonitem like so to make a "pull down" button: UIDeferredMenuElement *deferredmenuElement; deferredmenuElement = [UIDeferredMenuElement elementWithUncachedProvider:^(void (^ _Nonnull completion)(NSArray<UIMenuElement *> * _Nonnull)) { UIAction *actionOne = [UIAction actionWithTitle:@"Action One" image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) { NSLog(@"action one fired."); }]; UIAction *actionTwo = [UIAction actionWithTitle:@"Action Two" image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) { NSLog(@"action two fired."); }]; UIAction *actionThree = [UIAction actionWithTitle:@"Action Three" image:nil identifier:nil handler:^(__kindof UIAction * _Nonnull action) { NSLog(@"action three fired."); }]; completion(@[actionOne,actionTwo,actionThree]); }]; UIMenu *wrappedMenu = [UIMenu menuWithChildren:@[deferredmenuElement]]; UIBarButtonItem *uiBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:nil menu:wrappedMenu]; uiBarButtonItem.image = [UIImage systemImageNamed:@"rectangle.and.pencil.and.ellipsis"]; self.navigationItem.rightBarButtonItems = @[uiBarButtonItem]; The button appears in the toolbar but when I click it to expose the menu I get a menu with on element in it that says "Loading...". The the uncached provider block is never called. Running Ventura 13.2.1 and Xcode 14.2.
8
2
1.6k
Mar ’23