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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

iOS 18 Issue: When we add arm64 into Excluded Architecture and try to present screen, Screen will get froze and unable to select images.
I am using Storyboard to present a UIImagePickerController on a view controller (a simple initial view without any navigation or tab bar). Due to a requirement, we need to exclude the arm64 architecture. However, when I try to present the screen, it gets stuck. I am unable to select an image, and the screen becomes inaccessible. It's happening only on simulator. Does anyone have any solution.
1
0
314
Sep ’24
XCode or IOS 18 Bug?
I just finished updating my app to support the new screen sizes for the iPhone 16 series devices (iPhone16 Pro and iPhone 16 Pro Max). In testing the changes, I've come across what I hope is simply a bug in the Xcode 16 simulators. I don't have any actual devices (yet) that I can use to test. In landscape mode, my app presents a "tab" on the right side of the screen that can be tapped to bring out another view. Activating the tab is based on capturing the screen coordinates from a "tap". In Xcode 16, using the iPhone16 simulators on IOS 18, the area of the tab does not recognize that a tap has occurred. After hours of banging my head against my laptop, it dawned on me that the area of the screen that hosts the "tab" is in exactly the same location as "unavailable area" that represents the camera on the simulator. I have arrived at the assumption that the issue is that the simulator is treating the same space at the bottom of the device as it treats that reserved area at the top of the screen. Has anyone else experienced this? Is this a bug in the simulator or is this expected behavior on the iPhone 16 series devices?
3
1
716
Sep ’24
UICollectionView unwanted content offset change on invalidating layout
I have issue with unwanted changing offset in collection view to top or to near top. It is happening in collection view with vertical scroll when estimatedItemSize is not set to zero (main factor). If estimatedItemSize is zero it is always fine. It is SDK that provides items that should be loaded in few cells, items have dynamic height which is received from server and can be updated several times. Scenario when it happens (when was noticed) is 2 sections, in section 0 item is at index 4 of 14, section 1 is with only one cell with dynamic height item. If specific item is at index 0 in section 0 or have 1 cell per section (tried 15 sections and set items in sections 5 and 15) all is good regardless of estimatedItemSize. When new height is received if I call invalidateLayout or reloadItemAtIndexPaths it will “jump”. That same height is set in sizeForItemAtIndexPath. In some combinations it happens and in some not and that is the most annoying part. I tried setting estimated height to received height and it didn’t help (other cell may be smaller or larger). Also if I put items in one section at indexes 4 and 14 it “jumps”. I managed to make it work by setting at specific moment estimatedItemSize to zero then put back to one that SDK user set and didn’t see any issues but I was wondering if there is any other solution for this and did anyone had issue like this. It would be nice to have solution to keep one estimatedItemSize if it is not the default one (zero).
0
0
122
Sep ’24
Define the correct UIDocument subclass with the key UIDocumentClass
Hi there, I'm trying to migrate my app to using the UIDocumentViewController so I can use the new launch experience. My app exports a custom file type and uses UIDocument + UIDocumentBrowserViewController. I tried creating a UIDocumentViewController and making it the root view of my app but it doesn't recognise my custom document type. class Document_VC: UIDocumentViewController { var storyCardsDocument: PlotCardDocument? { self.document as? PlotCardDocument } override func viewDidLoad() { super.viewDidLoad() configureViewForCurrentDocument() } override func documentDidOpen() { configureViewForCurrentDocument() } func configureViewForCurrentDocument() { guard let document = storyCardsDocument, !document.documentState.contains(.closed) && isViewLoaded else { return } print("Document opened: \(document.fileURL)") } } The app opens but when I navigate to a document made in a previous version of the app it is greyed out. I also don't see a 'New' button in the launcher view. To try and see what I was doing wrong, I tested the markdown app sample code. When I make the UIDocumentViewController the root and try to open or create a new markdown document I get the following error: no document class found. Define the correct UIDocument subclass with the key UIDocumentClass in the info.plist's CFBundleDocumentTypes dictionary.
1
0
212
Sep ’24
UICardViewController does not load cells
I am making an IOS application using XCode Storyboard. I have a UICollectionViewController in the following structure UIViewController -> UIView -> UITabBarController -> UICollectionViewController The app loads without crashing, and UICollectionViewController.viewDidLoad() and .numberOfSections() execute correctly. But anything that I put in override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) does not seem to execute. Once the app loads, no cells load. And any print statement in the function doesn't execute either. All elements have their corresponding class correctly assigned in the Storyboard Identity Inspector, and the cells have the correct reusable identifier. How can I make it work correctly? My Collection View Controller: class ValidCardsCollectionViewController: UICollectionViewController { let dataSource: [String] = ["hearts", "clubs", "diamonds", "spades"] override func viewDidLoad() { super.viewDidLoad() print(dataSource) } override func numberOfSections(in collectionView: UICollectionView) -> Int { print("Loading \(dataSource.count) cells") return dataSource.count } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { var cell = UICollectionViewCell() if let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CardCell", for: indexPath) as? CardCollectionViewCell{ cardCell.configure(with: dataSource[indexPath.row]) cell = cardCell } print("loading cell") return cell } My UICollectionViewCell: class CardCollectionViewCell: UICollectionViewCell { @IBOutlet weak var lblStr: UILabel! func configure(with str:String){ lblStr.text = str } } Storyboard layout: Simulator:
3
0
167
Sep ’24
strange ios crash
HI i have found libsystem_kernel.dylib crash. i can't reproduce this error even this is not unrecognisable. here is stack trace Crashed: com.apple.main-thread 0 libsystem_kernel.dylib 0xaac mach_msg_trap + 8 1 libsystem_kernel.dylib 0x107c mach_msg + 72 2 CoreFoundation 0x6c88 + 368 3 CoreFoundation 0xaf90 + 1160 4 CoreFoundation 0x1e174 CFRunLoopRunSpecific + 572 5 GraphicsServices 0x1988 GSEventRunModal + 160 6 UIKitCore 0x4e5a88 + 1080 7 UIKitCore 0x27ef78 UIApplicationMain + 336 8 libTweaks.dylib 0x2a6b4 _apdecr_UIApplicationMain(int, char**, NSString*, NSString*) + 108 9 libswiftUIKit.dylib 0x27ee4 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 100 10 REDDI 0x214d6c main + 4368469356 (AppDelegate.swift:4368469356) 11 ??? 0x1028a84d0 (Missing)
1
0
185
Sep ’24
A glitch with retained view controllers on Catalyst
Hello! I discovered a bug on Catalyst about a three years ago but it still seems to be not fixed. My bug report number is FB9705748. The Internet is silent on this so I'm even not sure, perhaps it's only me. So to the problem. When you display UICollectionViewController or UIViewController that contains UICollectionView, interact with the collection view then dismiss the view controller, the displayed view controller isn't released if dismissal is done through navigation bar item. The problem occurs only when the run target is My Mac (Mac Catalyst). Everything is fine when you run on iOS or via My Mac (Designed for iPad). The sample project is uploaded to GitHub. It has a video that shows this strange behavior, see the log for 'deinit' messages. I did have some workaround to fix this but it stops to work, presumable on the new macOS. Also, chances are that it's not only UICollectionView which initiates the glitch, it's just that I only encounter it with collection views.
1
0
197
Sep ’24
[UITextView becomeFirstResponder] crash with [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
I am trying to set my UITextView as the first responder with [self.textView becomeFirstResponder] when my view controller called viewDidAppear. But sometimes it will cause crash with the error: [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0] all I did is just: - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.textView becomeFirstResponder]; } So if anyone can tell me what happened and how to do? when I call the [self.textView becomeFirstResponder], what will be insert into the responders list? self.textView itself? Thanks very much!
0
0
206
Sep ’24
Drag&Drop broken in iOS18.0?
Hi, I've encountered the following phenomenon when comparing drag&drop in iOS 18.0 with iOS 17.5: Let's say you have a small child view sitting on top of a larger parent view. In iOS 18.0, when hovering over the child view with a drag object and leaving the child view, the child view will propagate a "dropInteraction:sessionDidExit:" call to the UIDropInteractionDelegate of its parent view. The parent view now thinks, that the drag object is moved away from it (which is not the case!) and in turn its delegate doesn't receive any "dropInteraction:performDrop:" calls anymore. In iOS 17.5 this case is handled correctly (without "dropInteraction:sessionDidExit:" being propagated wrongly by child views to their parent views). Is this change in behavior intended or is this a bug?
1
0
211
Sep ’24
iOS App is crashing
My iOS app crashes, when kept idle in the background for sometime. Below is the detailed crash report. Incident Identifier: 90DF0404-7A1D-4AF3-8892-19AB744DF0FD Distributor ID: com.apple.AppStore Hardware Model: iPhone13,3 Process: Runner [35073] Path: /private/var/containers/Bundle/Application/894B2440-D20C-4C01-B278-A0DC4B199530/Runner.app/Runner Identifier: com.era.tk Version: 5.0.2 (5) AppStoreTools: 15F31e AppVariant: 1:iPhone13,3:15 Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.era.tk [793] Date/Time: 2024-09-25 13:17:31.3101 +0100 Launch Time: 2024-09-25 12:29:23.1866 +0100 OS Version: iPhone OS 17.6.1 (21G93) Release Type: User Baseband Version: 4.70.01 Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x0000000100c75e48 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [35073] Triggered by Thread: 0 Thread 0 Crashed: 0 Runner 0x0000000100c75e48 0x100c2c000 + 302664 1 Runner 0x0000000100c75e80 0x100c2c000 + 302720 2 UIKitCore 0x00000001a7e937e8 -[UIViewController _setViewAppearState:isAnimating:] + 1224 (UIViewController.m:6441) 3 UIKitCore 0x00000001a80520b0 -[UIViewController __viewWillDisappear:] + 108 (UIViewController.m:6705) 4 UIKitCore 0x00000001a8602cec -[UINavigationController _startCustomTransition:] + 1476 (UINavigationController.m:2260) 5 UIKitCore 0x00000001a7e97400 -[UINavigationController _startDeferredTransitionIfNeeded:] + 496 (UINavigationController.m:8062) 6 UIKitCore 0x00000001a7efc248 -[UINavigationController __viewWillLayoutSubviews] + 96 (UINavigationController.m:8369) 7 UIKitCore 0x00000001a81be688 -[UILayoutContainerView layoutSubviews] + 172 (UILayoutContainerView.m:89) 8 UIKitCore 0x00000001a7da7918 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1528 (UIView.m:20054) 9 QuartzCore 0x00000001a720626c CA::Layer::layout_if_needed(CA::Transaction*) + 504 (CALayer.mm:10816) 10 QuartzCore 0x00000001a7205df0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 (CALayer.mm:2598) 11 QuartzCore 0x00000001a7260fd8 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 (CAContextInternal.mm:2760) 12 QuartzCore 0x00000001a71d5ee0 CA::Transaction::commit() + 648 (CATransactionInternal.mm:432) 13 QuartzCore 0x00000001a721fc34 CA::Transaction::flush_as_runloop_observer(bool) + 88 (CATransactionInternal.mm:942) 14 UIKitCore 0x00000001a7e50ee8 _UIApplicationFlushCATransaction + 52 (UIApplication.m:3181) 15 UIKitCore 0x00000001a7e4e660 _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:119) 16 UIKitCore 0x00000001a7e4e2a4 schedulerStepScheduledMainSection + 172 (_UIUpdateScheduler.m:1058) 17 UIKitCore 0x00000001a7e4f148 runloopSourceCallback + 92 (_UIUpdateScheduler.m:1221) 18 CoreFoundation 0x00000001a5b6b834 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 (CFRunLoop.c:1957) 19 CoreFoundation 0x00000001a5b6b7c8 __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2001) 20 CoreFoundation 0x00000001a5b69298 __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2038) 21 CoreFoundation 0x00000001a5b68484 __CFRunLoopRun + 828 (CFRunLoop.c:2955) 22 CoreFoundation 0x00000001a5b67cd8 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420) 23 GraphicsServices 0x00000001ea5b51a8 GSEventRunModal + 164 (GSEvent.c:2196) 24 UIKitCore 0x00000001a81a1ae8 -[UIApplication _run] + 888 (UIApplication.m:3713) 25 UIKitCore 0x00000001a8255d98 UIApplicationMain + 340 (UIApplication.m:5303) 26 Runner 0x0000000100c4e660 0x100c2c000 + 140896 27 dyld 0x00000001c933f154 start + 2356 (dyldMain.cpp:1298)
1
0
177
Sep ’24
iOS 18 ShareExtension openURL:
When I write code in shareExtension like below: dispatch_async(dispatch_get_global_queue(0, 0), ^{ UIResponder *responder = [self nextResponder]; while ((responder = [responder nextResponder]) != nil) { if ([responder respondsToSelector:@selector(openURL:)] == YES) { [responder performSelector:@selector(openURL:) withObject:[NSURL URLWithString:APP_SCHEME]]; break; } } }); Will output in the console: BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(:) needs to migrate to the non-deprecated UIApplication.open(:options:completionHandler:). Force returning false (NO).
4
1
1.2k
Sep ’24
UISwitch initialization failure in SPM test for visionOS 2 & Xcode 16
In SPM package test running on visionOS 2, when creating a UISwitch we get a crash / error: Nil UISwitch visual element provided by <UISwitch: 0x102b15590; frame = (0 0; 0 0); layer = <CALayer: 0x6000004c1780>> (NSInternalInconsistencyException) This issue only occurs on visionOS 2 in Xcode 16 with Swift Package Manager. It works fine when running on visionOS 1.2 in Xcode 16 with SPM, as well as on iOS 18 in Xcode 16 with SPM. Additionally, running the test on visionOS inside of a non-SPM package (Project test) is also fine. What results you expected - The test should pass for UISwitch initialization on SPM for visionOS 2 on Xcode 16. What results you actually saw - Test failure with error - Nil UISwitch visual element provided by <UISwitch: 0x102b15590; frame = (0 0; 0 0); layer = <CALayer: 0x6000004c1780>> (NSInternalInconsistencyException) The version of Xcode you are using - Xcode 16 Feedback id - FB15254532
0
0
203
Sep ’24
UITabBarController didSelect item not working on iOS 18
I have been using the following function in my UITabBarController for several years, which runs some code when the user clicks a tab. I have now built the app using Xcode 16 and when I run it on my iPad with iPadOS 18, the function is not called. When I run the same app on iPadOS 16, it works just fine like it always has. Is this a bug, or is there something new that I need to do for iOS 18 support? override func tabBar(_tabBar: UITabBar, didSelect item: UITabBarItem) { // Some code } NOTE: My UITabBarController is presented from my root view controller, which is a UINavigationController.
2
1
402
Sep ’24
How to transition & resize a view from one view controller to another using UIKit & Snapshots?
I am trying to seamlessly transition a view from one view controller and have it "jump" into a sheet. Apple does this in their widget picker for example when you add one of the top widgets. Based on all the documentation I've read, the most common approach to this is to snapshot the area/view that you are trying to seamlessly transition in the presented view controller (the place where the item is coming from. And then have that snapshot translate across into where it should be in the layout of the presenting view controller. func makeAnimatorIfNeeded( using transitionContext: UIViewControllerContextTransitioning ) -> UIViewPropertyAnimator { if let animator = animator { return animator } // Presentation animation let animator = UIViewPropertyAnimator( duration: 0.5, timingParameters: UISpringTimingParameters(dampingRatio: 1.0) ) guard let fromVC = transitionContext.viewController(forKey: .from), let toVC = transitionContext.viewController(forKey: .to) else { transitionContext.completeTransition(false) return animator } /// !IMPORTANT: For some weird reason, accessing the views of the view controller /// directly, like `fromVC.view` or `toVC.view` will break the sheet transition and gestures. /// Instead, use the `view(forKey:)` method of the `transitionContext` to get the views. let fromView = transitionContext.view(forKey: .from) let toView = transitionContext.view(forKey: .to) let containerView = transitionContext.containerView let fromFrame = transitionContext.viewController(forKey: .from).map { transitionContext.finalFrame(for: $0) } ?? containerView.bounds let toFrame = transitionContext.viewController(forKey: .to).map { transitionContext.finalFrame(for: $0) } ?? containerView.bounds // Calculate the frame of sourceView relative to fromVC.view to capture the correct snapshot area. let snapshotFrameInFromVC = sourceView?.convert(sourceView?.frame ?? .zero, to: fromVC.view) ?? containerView.frame // Calculate the frame of sourceView relative to containerView to position the snapshot correctly. let snapshotFrameInContainer = sourceView?.convert(sourceView?.frame ?? .zero, to: containerView) ?? containerView.frame let snapshot: UIView? if isPresenting { // Create a snapshot of fromVC.view from the defined area (snapshotFrameInFromVC). let originalColor = fromVC.view.backgroundColor fromVC.view.backgroundColor = .clear snapshot = fromVC.view.resizableSnapshotView(from: snapshotFrameInFromVC, afterScreenUpdates: true, withCapInsets: .zero) fromVC.view.backgroundColor = originalColor // Position the snapshot correctly within the snapshot container snapshot?.frame = snapshotFrameInContainer toView?.frame = toFrame toView?.transform = CGAffineTransform(translationX: 0, y: containerView.frame.size.height) toView?.layoutIfNeeded() if let fromView { containerView.addSubview(fromView) } if let toView { containerView.addSubview(toView) containerView.addSubview(snapshot ?? UIView()) } let toViewCenter = CGPoint( x: toVC.view.bounds.midX, y: toVC.view.bounds.midY + 55 ) let gestureVelocity = CGPoint(x: 0, y: -5000) animator.addAnimations { Wave.animate( withSpring: self.animatedSpring, mode: .animated, gestureVelocity: gestureVelocity ) { snapshot?.animator.frame.size = CGSize(width: 204, height: 204) // Important to animate first snapshot?.animator.center = toViewCenter } completion: { finished, retargeted in print("finished: \(finished), retargeted: \(retargeted)") } toView?.transform = CGAffineTransform.identity } animator.addCompletion { animatingPosition in switch animatingPosition { case .end: snapshot?.removeFromSuperview() transitionContext.completeTransition(true) default: transitionContext.completeTransition(false) } } } else { // Transitioning view is fromView if let toView { containerView.addSubview(toView) } if let fromView { containerView.addSubview(fromView) } animator.addAnimations { fromView?.transform = CGAffineTransform(translationX: 0, y: containerView.frame.size.height) } animator.addCompletion { animatingPosition in switch animatingPosition { case .end: transitionContext.completeTransition(true) default: transitionContext.completeTransition(false) } } } self.animator = animator return animator } I can pull this off seamlessly if the animation involves a simple movement from A to B. But if I try to resize the snapshot as well, the snapshot becomes pixelated and low quality (I assume this is because the snapshot is literally a small screenshot and I'm stretching it from 56x56 to 204x204). Is there another way that I'm overlooking to pull this off without a snapshot? Or is there a way I can resize the snapshot without losing quality? Here is the animator code, it works great without the sizing so this should help future people looking to replicate the same effect anyways.
0
0
165
Sep ’24
Tapping a TextKit 2 backed UITextView moves the caret to a random location
With the upcoming launch of Apple Intelligence and Writing Tools, we've been forced to migrate our text editing app to TextKit 2. As soon as we released the update, we immediately got complaints about incorrect selection behaviour, where the user would tap a word to begin editing, but the caret would be shown in an undefined location, often dozens of paragraphs below the selected content. To reproduce: Create a UITextView backed by a standard TextKit 2 stack and a large amount of text (50,000+ words) - see sample project below Scroll quickly through the text view (at least 20% of the way down) Tap once to select a position in the document. Expected: The caret appears at the location the user tapped, and UITextView.selectedRange is the range of the text at the location of the tap. This is the behaviour of TextKit 1 based UITextViews. Actual: The caret is positioned at an undefined location (often completely off screen), and the selectedRange is different to the range at the location of the tap, often by several thousand. There is no pattern to the magnitude of the discrepancy. This incorrect behaviour occurs consistently in the sample project on the simulator, but you may need to hide the keyboard by pulling down, then repeat steps 2-3 a few times. This happens on iPhone and iPad, and on iOS 17, 18, and 18.1. Do you have any insight into why this might be happening or how to work around this issue? Sample code is here: https://github.com/nathantesler/textkit2-issue/tree/master
2
0
324
Sep ’24