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
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

Updating a NSTableView
For a Cocoa project I have this table view controller: @interface TableViewController : NSObject <NSTableViewDataSource, NSTableViewDelegate> @property (nonatomic, strong) NSMutableArray *numbers; @property (nonatomic, strong) NSMutableArray *letters; @end #import "TableViewController.h" @implementation TableViewController - (NSMutableArray *)numbers { if (!_numbers) { _numbers = [NSMutableArray arrayWithArray:@[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10"]]; } return _numbers; } - (NSMutableArray *)letters { if (!_letters) { _letters = [NSMutableArray arrayWithArray: @[@"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", @"j"]]; } return _letters; } // NSTableViewDataSource Protocol Method - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { return self.numbers.count; } // NSTableViewDelegate Protocol Method -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { NSString *identifier = tableColumn.identifier; NSTableCellView *cell = [tableView makeViewWithIdentifier:identifier owner:self]; if ([identifier isEqualToString:@"numbers"]) { cell.textField.stringValue = [self.numbers objectAtIndex:row]; } else { cell.textField.stringValue = [self.letters objectAtIndex:row]; } return cell; } In the storyboard I created a NSTableView and set up the connection, after running it I get what I expected: okay, cool, but I have a question: why is this working even though I haven't created a NSTableView as a property for my ViewController or for my TableViewController? Also, there's another problem, now I want to add a button to this window such that, every time I click it, a new item should be added to this table(for now it can be anything) So I created a button and a method for this and linked the action to the story board: -(IBAction) addNewNumber:(id)sender { [_numbers addObject:@"1234"]; [_letters addObject:@"testing"]; } Now, every time I click this button I can see that this method is indeed being called and that indeed IT IS adding a new member to these arrays, the thing is, the table is not being updated, what gives? Any advice on how I can fix this behavior?
1
0
660
Oct ’24
trailingSwipeActionsConfigurationProvider causes shadow effect on UICollectionViewListCell gone
Currently, I have achieve shadow and corner effect for UICollectionViewListCell, using the following code. UICollectionViewListCell class NoteCell: UICollectionViewListCell { override func awakeFromNib() { super.awakeFromNib() initShadow() initCorner() } private func updateShadowColor() { // Determine the shadow color based on the current interface style let shadowUIColor = UIColor.label self.layer.shadowColor = shadowUIColor.cgColor } private func initShadow() { // https://www.hackingwithswift.com/example-code/uikit/how-to-add-a-shadow-to-a-uiview self.layer.shadowOpacity = 0.3 self.layer.shadowOffset = CGSize(width: 0.5, height: 0.5) self.layer.shadowRadius = 2 self.layer.masksToBounds = false self.updateShadowColor() // Remove the following two lines if you experience any issues with shadow rendering: self.layer.shouldRasterize = true self.layer.rasterizationScale = UIScreen.main.scale } private func initCorner() { var backgroundConfig = UIBackgroundConfiguration.listPlainCell() backgroundConfig.backgroundColor = .systemBackground backgroundConfig.cornerRadius = 16 self.backgroundConfiguration = backgroundConfig } layout private func layoutConfig() -> UICollectionViewCompositionalLayout { let layout = UICollectionViewCompositionalLayout { section, layoutEnvironment in var config = UICollectionLayoutListConfiguration(appearance: .plain) config.headerMode = .none config.footerMode = .none config.showsSeparators = false config.headerTopPadding = 0 config.backgroundColor = nil config.trailingSwipeActionsConfigurationProvider = { [weak self] indexPath in guard let self = self else { return nil } // Knowing what we are tapping at. var snapshot = dataSource.snapshot() let sectionIdentifier = snapshot.sectionIdentifiers[indexPath.section] let itemIdentifiers = snapshot.itemIdentifiers(inSection: sectionIdentifier) let itemIdentifier: NoteWrapper = itemIdentifiers[indexPath.item] let deleteHandler: UIContextualAction.Handler = { action, view, completion in completion(true) // TODO: //snapshot.reloadItems([itemIdentifier]) } let deleteAction = UIContextualAction(style: .normal, title: "Trash", handler: deleteHandler) var swipeActionsConfiguration = UISwipeActionsConfiguration(actions: [ deleteAction, ]) deleteAction.image = UIImage(systemName: "trash") deleteAction.backgroundColor = UIColor.systemRed swipeActionsConfiguration.performsFirstActionWithFullSwipe = false return swipeActionsConfiguration } // https://developer.apple.com/forums/thread/759987 let layoutSection = NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) layoutSection.interGroupSpacing = 16 // Distance between item. layoutSection.contentInsets = NSDirectionalEdgeInsets( top: 16, // Distance between 1st item and its own header. leading: 16, bottom: 16, // Distance of last item and other header/ bottom edge. trailing: 16 ) return layoutSection } return layout } This is the outcome. However, when I perform swipe action, the shadow effect is gone. Do you have any idea how I can resolve such? Thanks.
0
0
363
Oct ’24
Users report that widgets are not working after iOS 18 update
I recently built a habit tracker app and got a few initial users. One of them reported that the widgets appear black and are not interactive. Does anyone know what might have happened to widgets in iOS 18 that could cause this issue? By the way, it works for me in the Simulator but not on a real device. How it supposed to work (simulator): https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExMWQ1N29sN2xvNnVjMjN5dGJqMHFxaGhtcGswaW43bTVvMnBmNW9wbSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/jevHq6JorR374YwuKF/giphy.gif How it actually works (real device): https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExaXNyZzRyYms4eG0yYzh0enF5ZXJyM29kN2VxMGszMHd4NTRkZnE1diZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/k4mVTFE84kdztbwlDV/giphy.gif
2
1
933
Oct ’24
How to connect SwiftUI state with UITable?
I use @Binding to sync data between SwiftUI component state and UITable state. my observations: while reordering @State variable of the TestView is updating, it can be checked by taping the button inside the table the data is not updating. 'log2' is always the same on reorder and which is more important the app crashes when I try to remove item. What to I missing? import SwiftUI import UIKit struct TestView: View { @State var items = ["item 1", "item 2", "item 3", "item 4", "item 5"] var body: some View { VStack { Button("Print Items") { print("log1", items) } ReorderableListView( items: $items ) { item in Text(item) } } } } private struct ReorderableListView<Content: View>: UIViewControllerRepresentable { @Binding var items: [String] let content: (String) -> Content class Coordinator: NSObject, UITableViewDataSource, UITableViewDelegate { var parent: ReorderableListView init(parent: ReorderableListView) { self.parent = parent } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { print("log2", parent.items) return parent.items.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) let hostingController = UIHostingController(rootView: parent.content(parent.items[indexPath.row])) hostingController.view.backgroundColor = .clear cell.contentView.subviews.forEach { $0.removeFromSuperview() } cell.contentView.addSubview(hostingController.view) cell.separatorInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15) if indexPath.row == self.parent.items.count - 1 { cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: .greatestFiniteMagnitude) } hostingController.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ hostingController.view.topAnchor.constraint(equalTo: cell.contentView.topAnchor), hostingController.view.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor), hostingController.view.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor) ]) return cell } func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { let movedObject = parent.items.remove(at: sourceIndexPath.row) parent.items.insert(movedObject, at: destinationIndexPath.row) } func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { return true } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { parent.items.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .automatic) } } } func makeCoordinator() -> Coordinator { Coordinator(parent: self) } func makeUIViewController(context: Context) -> UITableViewController { let tableViewController = UITableViewController() tableViewController.tableView.dataSource = context.coordinator tableViewController.tableView.delegate = context.coordinator tableViewController.tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: "Cell") tableViewController.tableView.isEditing = true return tableViewController } func updateUIViewController(_ uiViewController: UITableViewController, context: Context) { uiViewController.tableView.reloadData() } } private class CustomTableViewCell: UITableViewCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) } override func layoutSubviews() { super.layoutSubviews() superview?.subviews.filter({ "\(type(of: $0))" == "UIShadowView" }).forEach { (sv: UIView) in sv.removeFromSuperview() } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } #Preview { TestView() }
1
0
332
Oct ’24
could someone or an apple dev help me get data on an tableview in objective c?
I understand the mvc thing kinda, theres an array as a model, a tableview as a control, and the interface as a control (right?) so like, I drag an array controller on to the form display thing, assign a delegate to it the view and app module/header, add data to it and the tableview updates after I add a function to it? in vs the events are in the event browser, do I just copy and paste the code from the tutorial? how do I add controls and do all the advanced stuff? the documentation on developer.apple.com isnt that detailed, and most books are outdated or n/a since its objective c tutorials would be nice, some home grown method would be cool too thank you unidef warrell yashizzo
2
0
490
Oct ’24
DeviceActivityReport - Slow Synchronization. Screen time api, Family Controls
Hello! I am developing an app using the Screen Time API. Everything is good, but I have a problem with DeviceActivityReport. On the child’s device, stats are synced to the app in about 1-5 minutes. However, on the parent’s device, it can take around an hour or more. How can I make the stats sync faster between the child’s device and the parent’s device? How I Implemented It @Published var context: DeviceActivityReport.Context = .init("Time Limit") let filter = DeviceActivityFilter( segment: .daily( during: Calendar.current.dateInterval(of: .day, for: .now)! ), users: .children, devices: .all, applications: applicationTokens ) DeviceActivityReport(viewModel.context, filter: viewModel.filter) .frame(maxHeight: viewModel.maxReportHeight) In the Report Extension (Test Code) for await d in data { result += "device.name=\(d.device.name ?? "")" result += "\nuser.appleID=\(d.user.appleID ?? "")" result += "\ngivenName=\(d.user.nameComponents?.givenName ?? "")" result += "\nrole=\(d.user.role.rawValue)" for await activity in d.activitySegments { result += "\nactivitySegments hashValue=\(activity.hashValue)" result += "\ntotalActivityDuration=\(activity.totalActivityDuration)" result += "\ndateInterval=\(activity.dateInterval)" for await category in activity.categories { result += "\ncategory=\(category.category.localizedDisplayName ?? "")" for await app in category.applications { result += "\napp=\(app.application.bundleIdentifier ?? ""), time=\(app.totalActivityDuration)" } } } } Problems: activity.categories can be empty for a long time app.totalActivityDuration contains outdated information I need to wait about 1+ hours to get “actual” information.
1
0
491
Oct ’24
Clarification on New Transition Behavior of UIDocumentInteractionController in iOS 18: Feature or Bug?
Starting with iOS 18, there is a change in how the transition from an underlying view to a UIDocumentInteractionController’s preview view is animated. The transition now scales down the size of the content within the controller’s view, using the center point of the root view as the base of the transformation. This results in a smaller, compressed view centered within the root view, revealing the root view’s background, which is typically white. Even if this background color is adjusted to match elements like the navigation bar, the transformed view has non-rounded corners. I have not tested this behavior when presenting a UIDocumentInteractionController from a SwiftUI view. My question to the UIKit framework developers: Is this new behavior of UIDocumentInteractionController an intentional feature, a feature with bugs, or just a bug?
Topic: UI Frameworks SubTopic: UIKit
0
0
376
Oct ’24
Binding with ForEach or List doesn't work anymore when using @Observable macro
Hi. The binding in a ForEach or List view doesn't work anymore when using the @Observable macro to create the observable object. For example, the following are the modifications I introduced to the Apple's example called "Migrating from the Observable Object Protocol to the Observable Macro" https://developer.apple.com/documentation/swiftui/migrating-from-the-observable-object-protocol-to-the-observable-macro struct LibraryView: View { @Environment(Library.self) private var library var body: some View { List($library.books) { $book in BookView(book: book) } } } All I did was to add the $ to turn the reference to library.books into a binding but I got the error "Cannot find '$library' in scope" Is this a bug or the procedure to use binding in lists changed? Thanks
3
0
2.3k
Oct ’24
Remove rcp entity onReceive or by function
This is a follow up question for this post There are several entities I created in rcp that I want to play their animations in a sequence (the order is dynamic) My plan is to have onReceive detecting the notification, remove the current entity from the scene, add the next entity from the queue... Somehow, when I call removeFromParent()/removeChild(), either it is not removed or everything is removed and the app crashes, any tips?
1
0
313
Oct ’24
Getting an error on launching Carplay App - *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Application does not implement CarPlay template application lifecycle methods in its scene delegate.'
I have a SwiftUI app, and Apple has approved the Carplay entitlement. The entitlement integration is done successfully, however when I try to launch the carplay app I get the below error *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Application does not implement CarPlay template application lifecycle methods in its scene delegate.' Info.plist: UIApplicationSceneManifest UIApplicationSupportsMultipleScenes UISceneConfigurations CPTemplateApplicationSceneSessionRoleApplication UISceneConfigurationName Default Configuration UISceneDelegateClassName $(PRODUCT_MODULE_NAME).CarPlaySceneDelegate In AppDelegate I have the below func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { if connectingSceneSession.role == .carTemplateApplication { let sceneConfiguration = UISceneConfiguration(name: "CarPlay Scene", sessionRole: connectingSceneSession.role) sceneConfiguration.delegateClass = CarPlaySceneDelegate.self return sceneConfiguration } // Configuration for other types of scenes return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } Why am I getting the exception? Kindly suggest
1
0
669
Oct ’24
SwiftUI Previews broken on local Swift Package with dependencies
I have a project with two local packages One client package with an interface and some models with dynamic type in the Package.Swift One feature package with the UI and a dependency to the client package When I try to preview a view that is not using any models or code from the client package, it loads just fine e.g. a view that is just a container to display things like a card But when I tried to preview any other view that actually uses models from the client package, it just fails the first few lines of the preview error display LinkDylibError: Failed to build <filename>.swift Linking failed: linker command failed with exit code 1 (use -v to see invocation) ld: warning: search path '/Applications/Xcode-15.4.0.app/Contents/SharedFrameworks-iphonesimulator' not found Undefined symbols for architecture arm64: Also, I'm using Xcode 15.4 and iOS 17 as the min version
6
1
1.9k
Oct ’24
Navigation Bar animation upon Tab change
Hi. Since Xcode 16 and/or iOS 18.0 (I upgraded at the same time), I have an strange effect in the lower (let's say) 20% section of the Navigation Bar when changing to another tab, and this independently if large titles are used or not. Mentioned section is brighter or darker than the rest of the Navigation Bar background, depending on which background tint is used. This effect lasts about 0.3 seconds, but is clearly visible, quite disturbing and new as of Xcode 16 and/or iOS 18.0. I use the code below in AppDelegate to get a gradient coloured Navigation Bar background. let appearance = UINavigationBarAppearance() UINavigationBar.appearance().standardAppearance = appearance UINavigationBar.appearance().compactAppearance = appearance UINavigationBar.appearance().scrollEdgeAppearance = appearance UINavigationBar.appearance().compactScrollEdgeAppearance = appearance If I don't use above code., the background color is filled and without gradient. Subject effect doesn't show in this case. The effect basically looks like when changing tab, the new Navigation Bar background doesn't clear right away, and keeps the background from the previous Navigation Bar for 0.3 seconds before new one Navigation Bar background is rendered. I spent quite some time on changing every possible setting, in code as well as storyboard ... no success so far. Any ideas how to disable this undesired animation?
0
0
660
Oct ’24
AppLaunchTimeoutError
Hi. I tried to launch SwiftUI preview. But I got an error "AppLaunchTimeoutError" I attach the diagnostics. Does anyone know how to fix this problem? memo.txt
Topic: UI Frameworks SubTopic: SwiftUI
0
1
357
Oct ’24
Unable to import Charts in Xcode 16.1 beta 2
Failed to build module 'Charts'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.41 clang-1600.0.24.1)', while this compiler is 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.9.11 clang-1600.0.26.2)'). Please select a toolchain which matches the SDK. Any fix yet?
2
2
727
Oct ’24
Unable to compile SwiftUI Charts on Xcode 16.1 Beta 2
Unable to compile app that imports Swift UI Charts SDK on Xcode Version 16.1 beta 2 (16B5014f) with error: Failed to build module 'Charts'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.41 clang-1600.0.24.1)', while this compiler is 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.9.11 clang-1600.0.26.2)'). Please select a toolchain which matches the SDK. FB15161667
5
15
2.3k
Oct ’24
SwiftUI Charts not working in Xcode 16 Beta 2
Is there a way to workaround this issue? Can I revert back to Beta 1? Failed to build module 'Charts'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.41 clang-1600.0.24.1)', while this compiler is 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.9.11 clang-1600.0.26.2)'). Please select a toolchain which matches the SDK.
2
1
966
Oct ’24
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
1k
Oct ’24