Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

UIKit Documentation

Post

Replies

Boosts

Views

Activity

UIDocumentPickerViewController fullScreen not working
When I present a UIDocumentPickerViewController I want it to occupy the fullscreen but it never displays as fullscreen The modalPresentationStyle seems to have no effect no matter what I set it to Running the code with DispatchQueue.main.async did not help either Here is the code Anybody got any suggestions? `@objc private func plusButtonPressed() { DispatchQueue.main.async { let picker = UIDocumentPickerViewController(documentTypes: [kUTTypeData as String], in: .import) picker.delegate = self picker.modalPresentationStyle = .fullScreen self.present(picker, animated: true) } }`
0
0
411
Nov ’24
Typographic question for space character
In this UIKit app, I have to display numbers (from 1 to 100), in a label., on several lines, with 8 numbers on each line. Order is computed by the app for a specific purpose. The numbers are separated by space. Label font is Helvetica Neue 15.0. I want to get them aligned vertically. So, I have a padding so that they are all the same length of 4. Problem: the space have smaller width (half in fact) than digits, so alignment is disrupted: Of course, I can use fixed width fonts (like Menlo), but I've not found one that fits (the zero is barred, which is not looking great in the app). I have tried using class func monospacedDigitSystemFont( ofSize fontSize: CGFloat, weight: UIFont.Weight ) -> UIFont and apply to label.text. To no avail as it modifies only digits, not space char. I have found a workaround, padding with 2 spaces instead of one, but is there another solution ? So I am looking for a space character that would have the same width as a digit. There existe thin space (https://en.wikipedia.org/wiki/Whitespace_character) but not larger space. Does it exist ?
5
0
561
Nov ’24
UIDocumentPickerViewController: open to specific folder
Hi, With UIDocumentPickerViewController, there is a directoryURL property that says we can use to 'specify the starting directory for the document picker'. But it's not clear how to get the directory of a folder in iCloud Drive / Files app. How can I get the 'root' directory for a user's iCloud Drive or Dropbox folder, or the Downloads folder on their device, that I could pass to this directoryURL to make it easier for the user to pick their files? Thanks.
0
0
380
Nov ’24
prefersPointerLocked not worked properly if run on MacOS environment
Hi community. I am trying to adopt my first person shooter iOS game for running on MacOS environment. I need to lock the pointer when I enter battle mode, and unlock in lobby. On iOS all works fine (with mouse and keyboard) - pointer locks and unlocks according to my commands. However, on MacOS I faced the following behavior: after switching the pointer lock state and setNeedsUpdateOfPrefersPointerLocked invocation, the pointer does not locked immediately. To enable pointer lock, the user must click in the window. I checked the criteria listed in documentation: I do have fullscreen mode, I monitor UISceneActivationState and can confirm it is UISceneActivationStateForegroundActive, I do not use MacCatalyst (it is disabled in app's capabilities). However pointer locks only after click on window, which is weird. Can someone confirm that this is the exact behaviour as designed by Apple developers, or am I doing anything wrong. I have read the note: "Bringing an app built with Mac Catalyst to the foreground doesn’t immediately enable pointer lock. To enable pointer lock, the user must click in the window. To exit pointer lock, users can use Command-tab to switch to another app, or using Command-tilde.", but again, I don't use MacCatalyst. Any hints are highly appreciated! Best regards. refs: https://developer.apple.com/documentation/apple-silicon/running-your-ios-apps-in-macos https://developer.apple.com/documentation/uikit/uiviewcontroller/3601235-preferspointerlocked?language=objc
1
0
396
Nov ’24
Diffable Data Source Warning: Non-Thread Confined Updates
Hello, I’ve encountered a warning while working with UITableViewDiffableDataSource. Here’s the exact message: Warning: applying updates in a non-thread confined manner is dangerous and can lead to deadlocks. Please always submit updates either always on the main queue or always off the main queue - view=<UITableView: 0x7fd79192e200; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600003f3c9f0>; backgroundColor = <UIDynamicProviderColor: 0x60000319bf80; provider = <NSMallocBlock: 0x600003f0ce70>>; layer = <CALayer: 0x6000036e8fa0>; contentOffset: {0, -116}; contentSize: {375, 20}; adjustedContentInset: {116, 0, 49, 0}; dataSource: <TtGC5UIKit29UITableViewDiffableDataSourceOC17ArticleManagement21DiscardItemsViewModel17SectionIdentifierSS: 0x600003228270>> OS: iOS Version: iOS 17+, Xcode Version: 16.0, Frameworks: UIKit, Diffable Data Source, View: UITableView used with a UITableViewDiffableDataSource. Steps to Reproduce: Using a diffable data source with a table view. Applying snapshot updates in the data source from a main thread. Warning occurs intermittently during snapshot application. Expected Behavior: The snapshot should apply without warnings, provided the updates are on a main thread. Actual Behavior: The warning suggests thread safety issues when applying updates on non-thread-confined queues. Questions: Is there a recommended best practice to handle apply calls in diffable data sources with thread safety in mind? Could this lead to potential deadlocks if not addressed? Note :- I confirm I am always reloading / reconfiguring data source on main thread. Please find the attached screenshots for the reference. Any guidance or clarification would be greatly appreciated!
0
0
491
Nov ’24
UIKit Internal bug: Unbalanced call to _endOcclusion, please file a feedback report with any information you have that helps reproduce this bug!
Hi, I'm getting a bug in SwiftUI when dismissing a sheet and then hitting the back button or swiping to go back in a navigation stack. This issue happens inconsistently but causes undesirable behavior where the screen freezes in a partially dismissed state but does not crash. A user can click on another tab and return back and the view will have completed dismissal. The error seems more likely to happen if the time between dismissing the sheet and navigating backwards is minimal. I've experimenting using different forms of navigation, NavigationStack using NavigationPaths and NavigationDestinations, NavigationLinks, NavigationViews, etc. The issue persists. Is there a nice fix or intended fix to this issue coming soon? Thank you!
1
0
287
Nov ’24
Potential Issue in "Display Distinct Layouts Per Section" Documentation Example
Hi everyone, I was exploring the Display Distinct Layouts Per Section section of the Apple documentation and noticed a potential issue in the example code provided. Specifically, in the createLayout method of the TwoColumnViewController in the sample project, the item size appears to be incorrectly described. The documentation states that the item size is ignored because the items are organized in columns, but in practice, the size is considered. When running the sample project without any modifications, the layout doesn't behave as described or expected. Here’s what I observed: The items are not displayed as intended in a two-column layout. Modifying the item size explicitly affects the layout, contrary to the documentation's claim that the size is ignored. This seems to be a mismatch between the documentation and the actual implementation. Could this be clarified or corrected? Has anyone else encountered this issue? If so, are there any recommended adjustments to the sample code to achieve the intended layout? Thanks in advance for any insights or updates on this! https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/implementing_modern_collection_views#4461906
0
2
229
Nov ’24
[SWIFT] Accessing and controlling @IBOutlet variables from other ViewControllers.
I am having trouble accessing and controlling @IBOutlet variables from other ViewControllers. More specifically, I want to control that @IBOutlet variable based on real-time changes in the variable value of another ViewController. Control is possible in the viewcontainer that contains the @IBOutlet variable, but when trying to control it from another viewcontainer, the message "Thead1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value" appears. Is there any possible way to do it? I think this will be difficult since thread1 in the error message means the main thread, so I tried to create a thread in the viewcontainer that has the @IBOutlet variable and access the variable of another viewcontainer to control the @IBOutlet variable inside the thread, but in this case, the variable value of the other viewcontainer that changes in real time is fixed to the value at the moment the thread is created, and the value that changes in real time after that cannot be retrieved. And I don't think using threads for this purpose is a good way. I sincerely ask for help from all the experts. If I can solve this, it will be easy to create the rest of the app structure. Sincerely !
1
1
296
Nov ’24
shouldAutomaticallyForwardAppearanceMethods returns NO by default in UITabBarController, but documentation states YES
Hi all, I’ve been facing a behavior issue with shouldAutomaticallyForwardAppearanceMethods in UITabBarController. According to Apple’s documentation, this property should default to YES, which means that the appearance lifecycle methods (like viewWillAppear and viewDidAppear) should be automatically forwarded to child view controllers. However, in my current development environment, I’ve noticed that shouldAutomaticallyForwardAppearanceMethods returns NO by default in UITabBarController, and this is causing some issues with lifecycle management in my app. I even tested this behavior in several projects, both in Swift and Objective-C, and the result is consistent. Here are some details about my setup: I’m using Xcode 16.0 with iOS 16.4 Simulator. I’ve tested the behavior in both a new UIKit project and a simple SwiftUI project that uses a UITabBarController. Even with a clean new project, the value of shouldAutomaticallyForwardAppearanceMethods is NO by default. This behavior contradicts the official documentation, which states that it should be YES by default. Could someone clarify if this is expected behavior in newer versions of iOS or if there is a known issue regarding this? Any help or clarification would be greatly appreciated! Thanks in advance!
1
0
309
Nov ’24
Live Acitivities - ProgressView problem
Hello i ve implemented progressview and updating the state via push notification. the progress view wants closedrange which i followed but whenever i get update, the progress value resets to beginning my range is like : Date.now..endDate but i dont get it, lets assume that i get the date from database and initialized already then how the code will understand that what progress value will be as current ? it has to be something like i suppose : startDate..Date.now..endDate thanks
0
0
346
Nov ’24
How the input of UITextField is stored ?
When user enters in a textfield, is the input of textfield gets stored in a String ? If yes, then String in swift being immutable, as user keeps on typing does new memory for storing that text gets allocated with each key stroke ? And when we read users input by using delegate method textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) from textfield.text, we get users input in a String. Is it same storage as used by textfield for storing the user input on key stroke or is it some other storage with copy of the user's input in it? Or is UItextfield using a diffrent data structure (buffer) for storing the user input and when we do textfield.text, it gives a copy of data stored in original buffer?
1
0
521
Nov ’24
Fatal Exception: NSInternalInconsistencyException Attempting to select a view controller that isn't a child! (null)
When call: [UITabBarController setViewControllers:animated:] It crashed and raise an Fatal Exception: Fatal Exception: NSInternalInconsistencyException Attempting to select a view controller that isn't a child! (null) the crash stack is: Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x8408c __exceptionPreprocess 1 libobjc.A.dylib 0x172e4 objc_exception_throw 2 Foundation 0x82215c _userInfoForFileAndLine 3 UIKitCore 0x38a468 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] 4 UIKitCore 0x3fa8a4 -[UITabBarController _setSelectedViewController:performUpdates:] 5 UIKitCore 0x3fa710 -[UITabBarController setSelectedIndex:] 6 UIKitCore 0x8a5fc +[UIView(Animation) performWithoutAnimation:] 7 UIKitCore 0x3e54e0 -[UITabBarController _setViewControllers:animated:] 8 UIKitCore 0x45d7a0 -[UITabBarController setViewControllers:animated:] And it appear sometimes, what's the root cause?
3
1
529
Nov ’24
NSInternalInconsistencyException Failed to create remote render context
Some crashes were found, not many, but we could not locate the specific code because the error stack is a systematic method. Error: NSInternalInconsistencyException Failed to create remote render context Stack: 0 CoreFoundation 0x000000018a879d78 ___exceptionPreprocess + 220 1 libobjc.A.dylib 0x00000001a34de734 _objc_exception_throw + 60 2 Foundation 0x000000018c0ff358 -[NSMutableDictionary(NSMutableDictionary) initWithContentsOfFile:] + 0 3 UIKitCore 0x000000018d475f8c ___UIKIT_DID_NOT_RECEIVE_A_REMOTE_CACONTEXT_FROM_COREANIMATION_INDICATING_A_POSSIBLE_BACKBOARDD_CRASH + 572 4 UIKitCore 0x000000018d232484 ___UIKIT_IS_REQUESTING_A_CACONTEXT_FROM_COREANIMATION + 80 5 UIKitCore 0x000000018d1fc32c +[_UIContextBinder createContextForBindable:withSubstrate:] + 708 6 UIKitCore 0x000000018d13bdec -[_UIContextBinder _contextForBindable:] + 148 7 UIKitCore 0x000000018cf5bd20 -[_UIContextBinder updateBindableOrderWithTest:force:] + 480 8 UIKitCore 0x000000018d2e1200 -[_UIContextBinder createContextsWithTest:creationAction:] + 92 9 UIKitCore 0x000000018ccd64c0 -[UIWindowScene _prepareForResume] + 156 10 UIKitCore 0x000000018ce2ef80 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 876 11 UIKitCore 0x000000018ce72528 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 288 12 UIKitCore 0x000000018cdfc8c8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 476 13 FrontBoardServices 0x000000019c9dbe18 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 528 14 FrontBoardServices 0x000000019c9f413c ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152 15 FrontBoardServices 0x000000019c9d9308 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240 16 FrontBoardServices 0x000000019c9df824 ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 396 17 libdispatch.dylib 0x000000018a4e0a2c __dispatch_client_callout + 20 18 libdispatch.dylib 0x000000018a4e44e0 __dispatch_block_invoke_direct + 264 19 FrontBoardServices 0x000000019c9dac70 ___FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48 20 FrontBoardServices 0x000000019c9da040 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220 21 FrontBoardServices 0x000000019c9de700 -[FBSSerialQueue _performNextFromRunLoopSource] + 28 22 CoreFoundation 0x000000018a89bf04 ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 23 CoreFoundation 0x000000018a8acc90 ___CFRunLoopDoSource0 + 208 24 CoreFoundation 0x000000018a7e6184 ___CFRunLoopDoSources0 + 268 25 CoreFoundation 0x000000018a7ebb4c ___CFRunLoopRun + 828 26 CoreFoundation 0x000000018a7ff6b8 _CFRunLoopRunSpecific + 600 27 GraphicsServices 0x00000001a6899374 _GSEventRunModal + 164 28 UIKitCore 0x000000018d164e88 -[UIApplication _run] + 1100 29 UIKitCore 0x000000018cee65ec _UIApplicationMain + 364 30 ??? 0x00000001059b9ce4 0x00000001059b9ce4 + 0 These crashes occurred when the App was about to enter the foreground. (UIApplicationWillEnterForegroundNotification) These crashes occurred on systems from 15 to 18. crash.log
1
0
270
Nov ’24
MTKView delegate ownership during view controller transitions
The Problem When transitioning between view controllers that each have their own MTKView but share a Metal renderer backend, we run into delegate ownership conflicts. Only one MTKView can successfully render at a time, since setting the delegate on one view requires removing it from the other, leading to paused views during transitions. For my app, I need to display the same visuals across multiple views and have them all render correctly. Current Implementation Approach I've created a container object that manages the MTKView and its relationship with the shared renderer: class RenderContainer { let metalView: MTKView private let renderer: MetalRenderer func startRendering() { metalView.delegate = renderer metalView.isPaused = false } func stopRendering() { metalView.isPaused = true metalView.delegate = nil } } View controllers manage the rendering lifecycle in their view appearance methods: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) renderContainer.startRendering() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) renderContainer.stopRendering() } Observations & Issues During view controller transitions, one MTKView must stop rendering before the other can start. Also there is no guarantee that the old view will stop rendering before the new one starts, with the current API design. This creates a visual "pop" during animated transitions Setting isPaused = true helps prevent unnecessary render calls but doesn't solve the core delegate ownership problem The shared renderer maintains its state but can only output to one view at a time Questions What's the recommended approach for handling MTKView delegate ownership during animated transitions? Are there ways to maintain visual continuity without complex view hierarchies? Should I consider alternative architectures for sharing the Metal content between views? Any insights for this scenario would be appreciated.
1
0
450
Nov ’24
Limiting UITableView Width Across Different Table View Configurations
I have an iOS App which looks great on iPhone, portrait only, which makes a lot of use of UITableViews. On iPad those tables look stretched out in Landscape. On MacOS with Apple Silicon the app can be resized to any size and the table views look very stretched. There are views in the App which users want to resize so limiting app size not an option. I've been modifying the app's table views to limit their width and centre them using constraints. This isn't easy, it's a lot of work as UITableViewController doesn't allow for constraining the table width. Or does it? So I've changed them to UIViewControllers with UITableView imbedded in the root UIView with constraints. Looks really nice. Now I've just run into the limitation that static tables, which I have a number of, aren't allowed to be embedded. So how can I limit the width of them? I really don't want to add a lot of dynamic code. Please tell me there's an simpler, more elegant method to what really makes a much more aesthetically pleasing UI on iOS App running on iPad and MacOS? TIA!
3
0
412
Nov ’24
UITableViewDropItem missing in Xcode 16?
Following instructions from ChatGPT, I'm trying to rearrange the order of rows in a UITableView. - (void)tableView:(UITableView *)tableView performDropWithCoordinator:(id<UITableViewDropCoordinator>)coordinator { NSIndexPath *destinationIndexPath = coordinator.destinationIndexPath ?: [NSIndexPath indexPathForRow:self.items.count inSection:0]; [tableView performBatchUpdates:^{ for (UITableViewDropItem *dropItem in coordinator.items) { NSString *movedItem = dropItem.dragItem.localObject; if (movedItem) { NSIndexPath *sourceIndexPath = dropItem.sourceIndexPath; if (sourceIndexPath) { [self.items removeObjectAtIndex:sourceIndexPath.row]; [self.items insertObject:movedItem atIndex:destinationIndexPath.row]; [tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath]; } } } } completion:nil]; } Xcode is complaining that UITableViewDropItem does not exist. The class is in all the documentation, it is just not showing up when needed! Suggestions?
1
0
289
Nov ’24