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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

Regression: Autocorrect suggestions sometimes eat touch events
If Autocorrect is showing a potential correction, sometimes tapping elsewhere in the UI causes the suggestion to be accepted, but the touch event is not passed to the tapped view. A screen recording from a sample app demonstrating the issue is available here. I first type "Coffee", which does not show an autocorrect suggestion and then I tap on a table row, which successfully shows an alert. I then type "Coffeesc", which shows an autocorrect suggestion. Then when I tap on one of the table rows, the autocorrect suggestion is accepted, but our implementation of tableView:didSelectRowAtIndexPath: is not called and no alert is shown. The issue began in iOS 17.1 and only occurred when the Predictive Text switch in Settings -> General -> Keyboard was OFF. However, the issue still occurs in iOS 18 beta 3 and now I'm able to reproduce the issue when the Predictive Text switch is ON. I filed FB13418977 about the issue back in November (including the sample project shown in the video that reproduces the issue), but there have been no comments from Apple in the bug report. I initiated a code-level support request in April, but was told DTS did not have a workaround and that I should just continue to follow the bug report for updates. This bug impacts the primary text field in our app, but since Predictive Text is enabled by default, it hasn't impacted a large number of our customers on iOS 17. And for users that were impacted, we were able to tell them to enable Predictive Text as a workaround until the bug is fixed. With the issue occurring even when Predictive Text is ON in the iOS 18 betas, the text field is now nearly impossible to use. The only workaround I can think of is turning off autocorrect for that text field, but that isn’t a great solution, as it leads to a significant increase in typos when the user types multiple words. We would desperately like for this to be fixed in iOS 18, but if someone at Apple could please look at FB13418977 and at least provide us with an update or potential workaround, it would be greatly appreciated. Thank you and please let me know if you need any additional information.
0
0
146
1w
Prevent Large Title from Moving Down when Refreshing TableView
I have implemented the Large Title for UITableView correctly. The Navigation bar collapses when scrolling down the table view. However, when pulling to refresh, the Large Title moves down the screen instead of staying stationary. I suspect that this is the default behavior. Is there a way to keep the large title stationary when pulling downward to refresh the UITableView?
0
0
145
1w
Poor App Store/TestFlight Build Scrolling Performance
We are experiencing a particularly niche issue where the scrolling performance for one of our table/collection views severely lags, but only for App Store and TestFlight builds. For all local builds and the internal builds we create for our QE team, the scrolling performance is smooth and free of any issues. It's only when the app is distributed through TestFlight or the App Store do we see this issue. We've gone over the build settings a number of times and have practically ruled out any differences between local builds, builds provided to QE, and builds that are uploaded to the App Store/TestFlight. All builds are effectively identical. We have tried to reproduce this issue locally, but to no avail. We're not able to take an App Store or TestFlight build and profile or debug it locally, so we're pretty much at a loss in terms of how to proceed and resolve this issue. Is this an issue that's been encountered before? Any advice on how to proceed?
0
1
134
1w
App crash: Inconsistency in UITabBar items and view controllers detected. No view controller matches the UITabBarItem.
Several users are seeing a crash in a new app version that introduces the use of a UITabBarController. We haven't been able to isolate the crash to a specific user flow, device, or OS version. Fatal Exception: NSInternalInconsistencyException Inconsistency in UITabBar items and view controllers detected. No view controller matches the UITabBarItem '<UITabBarItem: 0x130623160> title='Today' image=<UIImage:0x3001893b0 named(RootTab-resources: today) {36, 32} renderingMode=automatic(original)> selected'. 0 CoreFoundation 0x83f20 __exceptionPreprocess 1 libobjc.A.dylib 0x16018 objc_exception_throw 2 Foundation 0x6de868 _userInfoForFileAndLine 3 UIKitCore 0x85c9d8 -[UITabBarController _viewControllerForTabBarItem:] 4 UIKitCore 0x85ca80 -[UITabBarController _tabBarItemClicked:] 5 UIKitCore 0x3fb31c -[UIApplication sendAction:to:from:forEvent:] 6 UIKitCore 0x785d18 -[UITabBar _sendAction:withEvent:] 7 UIKitCore 0x3fb31c -[UIApplication sendAction:to:from:forEvent:] 8 UIKitCore 0x3fb1f4 -[UIControl sendAction:to:forEvent:] 9 UIKitCore 0x3fb044 -[UIControl _sendActionsForEvents:withEvent:] 10 UIKitCore 0x787054 -[UITabBar _buttonUp:] 11 UIKitCore 0x3fb31c -[UIApplication sendAction:to:from:forEvent:] 12 UIKitCore 0x3fb1f4 -[UIControl sendAction:to:forEvent:] 13 UIKitCore 0x3fb044 -[UIControl _sendActionsForEvents:withEvent:] 14 UIKitCore 0x913894 -[UIControl touchesEnded:withEvent:] 15 UIKitCore 0x33beac -[UIWindow _sendTouchesForEvent:] 16 UIKitCore 0x33b954 -[UIWindow sendEvent:] 17 UIKitCore 0x1bc9e0 -[UIApplication sendEvent:] 18 UIKitCore 0x1be1d4 __dispatchPreprocessedEventFromEventQueue 19 UIKitCore 0x1c6ecc __processEventQueue 20 UIKitCore 0xb984c updateCycleEntry 21 UIKitCore 0xb776c _UIUpdateSequenceRun 22 UIKitCore 0xb73b0 schedulerStepScheduledMainSection 23 UIKitCore 0xb8254 runloopSourceCallback 24 CoreFoundation 0x56834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ 25 CoreFoundation 0x567c8 __CFRunLoopDoSource0 26 CoreFoundation 0x54298 __CFRunLoopDoSources0 27 CoreFoundation 0x53484 __CFRunLoopRun 28 CoreFoundation 0x52cd8 CFRunLoopRunSpecific 29 GraphicsServices 0x11a8 GSEventRunModal 30 UIKitCore 0x40a90c -[UIApplication _run] 31 UIKitCore 0x4be9d0 UIApplicationMain 32 Coach 0x62a44 main + 14 (main.m:14) 33 ??? 0x1bcfd9e4c (Missing) I have only found 2 references to this exception online and neither of them have a resolution: https://stackoverflow.com/questions/77536249/embed-flutterviewcontroller-to-native-swift-tabbar https://github-com.translate.goog/ChenYilong/CYLTabBarController/issues/608?_x_tr_sl=zh-CN&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=sc Any ideas on how this can be further investigated or resolved?
2
0
188
1w
Custom Width of sheet in landscape [UiKit]
I am using UISheetPresentationController to present a sheet. Everything works fine except I am not able to modify width of the sheet in landscape mode. As per design the width has to be 60% of the view bounds. In Apple talk: https://developer.apple.com/videos/play/wwdc2021/10063/ It is mentioned that we can resize sheet to preferredContentSize if this flag is set to true: sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true But this does not work. Here is my code: class BottomSheetController<Content: View>: UIViewController { private var hostingController: UIHostingController<Content>? init( content: @escaping () -> Content) { self.hostingController = UIHostingController(rootView: content()) super.init(nibName: nil, bundle: nil) configureSheetProperties() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() guard let hostingController = hostingController else { return } addChild(hostingController) view.addSubview(hostingController.view) hostingController.didMove(toParent: self) hostingController.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ hostingController.view.topAnchor.constraint(equalTo: view.topAnchor), hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) } private func configureSheetProperties() { modalPresentationStyle = .pageSheet preferredContentSize = CGSize(width: view.bounds.width * 0.6, height: view.bounds.height) if let sheet = sheetPresentationController { sheet.prefersGrabberVisible = true sheet.prefersScrollingExpandsWhenScrolledToEdge = false sheet.prefersEdgeAttachedInCompactHeight = true sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true sheet.preferredCornerRadius = 20 sheet.detents = [.medium()] } } open override var preferredContentSize: CGSize { get { return CGSize(width: view.bounds.width * 0.6, height: super.preferredContentSize.height) } set { super.preferredContentSize = CGSize(width: view.bounds.width * 0.6, height: newValue.height) } } }
1
0
104
1w
UIApplication Background Task Behavior
I just read Quinn "The Eskimo!"'s great post on UIApplication Background Task Notes. A couple further points of clarification that would be useful: Is it guaranteed that the expiration handler will only be invoked after beginBackgroundTask(expirationHandler:) returns? Is it safe to invoke endBackgroundTask(_:) more than once for a given identifier?
0
0
110
1w
How to change selected tab title color in iPadOS 18?
I applied image tint color to TabBar. It works fine when I decrease the window width using stage manager. Also it shows proper in iPhone. But it doesn't show orange title in compact style. I also tried below things: self.tabBar.tintColor = .orange self.tabBar.unselectedItemTintColor = .gray The only solution is to set AccentColor in Assets.xcassets. But what if I want to change different color than AccentColor?
1
0
152
1w
UITableViewDiffableDataSource apply snapshot crashes on iOS 17
Hello all, We got app crashes on dataSource.apply(snapshot, animatingDifferences: false) after refactoring our tableView code to UITableViewDiffableDataSource. This doesn't happen every time. DispatchQueue.main.async { [weak self] in guard let self = self else { return } var snapshot = getCurrentSnapshot() snapshot.deleteItems([...]) snapshot.appendItems([...], toSection: section) dataSource.apply(snapshot, animatingDifferences: false) } And the controller has deallocated before it. Crash log: controller (0x110a64800): deallocated *** Assertion failure in NSInteger _UITableViewRowDataNumberOfRowsInSection(UITableViewRowData *__unsafe_unretained, NSInteger)(), UITableViewRowData.m:1761 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requested the number of rows for section (4) which is out of bounds.' *** First throw call stack: ( 0 CoreFoundation 0x0000000180491128 __exceptionPreprocess + 172 1 libobjc.A.dylib 0x000000018008412c objc_exception_throw + 56 2 Foundation 0x0000000180d11770 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0 3 UIKitCore 0x0000000185538ad0 -[UITableViewRowData numberOfRowsInSection:] + 260 4 UIKitCore 0x00000001855052f0 -[UITableView _shouldDrawSeparatorAtBottomOfSectionForCellAtIndexPath:] + 152 5 UIKitCore 0x0000000185504dbc -[UITableView _updateSeparatorStateForCell:atIndexPath:] + 100 6 UIKitCore 0x0000000185504cf0 -[UITableView _updateSeparatorStateForVisibleCells] + 188 7 UIKitCore 0x00000001854f4bd0 -[UITableView _updateAnimationDidStopWithOldVisibleViews:finished:context:] + 1108 8 UIKitCore 0x00000001854f2630 __46-[UITableView _updateWithItems:updateSupport:]_block_invoke_4 + 36 9 UIKitCore 0x00000001857fcb1c __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 28 10 UIKitCore 0x00000001857fce24 -[UIViewAnimationBlockDelegate _sendDeferredCompletion:] + 100 11 libdispatch.dylib 0x000000010e5100f0 _dispatch_call_block_and_release + 24 12 libdispatch.dylib 0x000000010e51193c _dispatch_client_callout + 16 13 libdispatch.dylib 0x000000010e5215e4 _dispatch_main_queue_drain + 1228 14 libdispatch.dylib 0x000000010e521108 _dispatch_main_queue_callback_4CF + 40 15 CoreFoundation 0x00000001803f1a30 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 16 CoreFoundation 0x00000001803ec148 __CFRunLoopRun + 1936 17 CoreFoundation 0x00000001803eb5a4 CFRunLoopRunSpecific + 572 18 GraphicsServices 0x000000018e9fbae4 GSEventRunModal + 160 19 UIKitCore 0x00000001852f02e4 -[UIApplication _run] + 868 20 UIKitCore 0x00000001852f3f5c UIApplicationMain + 124 21 appName 0x0000000103e8b0dc $s22appNameySpySpys4Int8VGGXEfU_ + 192 22 appName 0x0000000103e8b480 _swift_se0333_UnsafeMutablePointer_withMemoryRebound + 900 23 appName 0x0000000103e8af30 main + 1320 24 dyld 0x000000010e409544 start_sim + 20 25 ??? 0x000000010e61a0e0 0x0 + 4536246496 26 ??? 0xca54000000000000 0x0 + 14579277893705138176 ) libc++abi: terminating due to uncaught exception of type NSException
2
0
172
1w
Modifying the view hierarchy of a UITableViewCell as part of reloadData
I am trying to debug a crash due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSFrozenDictionary layoutSublayers]: unrecognized selector sent to instance. I see 2 things that I find interesting about it. The fact that the instance is a __NSFrozenDictionary tells me that the reference to a CALayer that has since been evicted from memory and re-written. The call to layoutSublayers tells me that the CALayer was dealloc-ed at some point between the call to setNeedsLayout (or layoutIfNeeded) This seemingly occurs as part of a call to -[UITableView reloadData] Furthermore, each cell created by the UITableView has a UIStackView. As part of the call to cellForRowAtIndexPath the code adds an instance of "custom view" to the stack view's subviews. As part of the call to prepareForReuse the code removes the "custom view" from the stack view's subviews. Therefore as part of the prepareForReuse the "custom view" (and its layer) is evicted from memory. My theory is that the tableview does a layout pass on the visible cell which has since had its subview removed which causes the crash. My question is what are the constraints on when/where to call reloadData and/or when/where you should definitely avoid it as it relates to this context? This is code that modifies the view hierarchy of the cell as part of its lifecycle which AFAIK this is "not supported" since prepareForReuse is meant to be used for resetting view state and cellForRowAtIndexPath to reset content. In that sense, another question, are you not allowed to modify the cell view hierarchy period as part of the cycle to draw the visible cells or is it more of a case, do not call reloadData?
2
0
173
1w
Crash on TextField
A crash when Use UITextfield to display special characters "美҈̛̍̐̃͒̑́̌̆̾̒̿̒̚̚҈҉̵̶̸̷̷҇̒́̎͐͊̎̑̆́̓̽͂̊͋̑͛͑̈́̉̄̿́̏̽̎̓̋̓́̀̿͒͗͐̇҇͌̏͛͐̈́̑̀̏̏̋̏͑̊͋̈́̉̃̀̉͌̾̍͐͊̃́̉̍̈̎̒̊̉̚̕̚͠͝͠ 】". the system is iOS 16.3.1 and iOS 17.5.1 0 CoreFoundation ___exceptionPreprocess + 164 1 libobjc.A.dylib _objc_exception_throw + 60 2 Foundation _blockForLocation 3 UIFoundation -[NSTextLineFragment _defaultRenderingAttributesAtCharacterIndex:effectiveRange:] + 104 4 UIFoundation ___53-[NSTextLineFragment initWithAttributedString:range:]_block_invoke + 72 5 CoreText TLine::DrawGlyphsWithAttributeOverrides(CGContext*, __CFDictionary const* ( block_pointer)(long, CFRange*), void ( block_pointer)(CTLineDecorationType, void const*, bool, double, double, double, int, CGPoint, CFRange)) const + 424 6 UIFoundation __NSCoreTypesetterRenderLine + 368 7 UIFoundation -[NSTextLineFragment drawAtPoint:graphicsContext:] + 164 8 UIFoundation -[NSTextLineFragment drawAtPoint:inContext:] + 88 9 UIFoundation -[NSTextLayoutFragment drawAtPoint:inContext:] + 244 10 UIKitCore __UITextCanvasDrawWithFadedEdgesInContext + 256 11 UIKitCore -[_UITextLayoutFragmentView drawRect:] + 228 12 UIKitCore -[UIView(CALayerDelegate) drawLayer:inContext:] + 508 13 QuartzCore CABackingStoreUpdate + 252 14 QuartzCore ___ZN2CA5Layer8display_Ev_block_invoke + 64 15 QuartzCore -[CALayer _display] + 1636 16 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 416 17 QuartzCore CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 18 QuartzCore CA::Transaction::commit() + 648 19 QuartzCore CA::Transaction::flush_as_runloop_observer(bool) + 88 20 UIKitCore __UIApplicationFlushCATransaction + 52 21 UIKitCore __UIUpdateSequenceRun + 84 22 UIKitCore _schedulerStepScheduledMainSection + 172 23 UIKitCore _runloopSourceCallback + 92 24 CoreFoundation _CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 25 CoreFoundation ___CFRunLoopDoSource0 + 176 26 CoreFoundation ___CFRunLoopDoSources0 + 244 27 CoreFoundation ___CFRunLoopRun + 828 28 CoreFoundation _CFRunLoopRunSpecific + 608 29 GraphicsServices _GSEventRunModal + 164 30 UIKitCore -[UIApplication _run] + 888 31 UIKitCore _UIApplicationMain + 340 32 UIKitCore _keypath_get_selector_hoverStyle + 11024
1
0
149
1w
Issue with 24-hour time format in UIDatePicker and possible workarounds
Dear Apple Support Team, I am currently developing a control in my app that uses UIDatePicker for time input. To ensure that the time display format is consistently in 24-hour notation regardless of the region, I have set the locale of UIDatePicker to ‘systemLocale’. However, while this worked as expected up to iPadOS15, displaying the time in 24-hour format, it has switched to a 12-hour format from iPadOS16 onwards. I am wondering if there have been any changes in the behavior of UIDatePicker’s locale between the updates from iPadOS15 to iPadOS16? Additionally, I would like to know if there are any workarounds to this issue that do not involve modifying the program. In other words, is there a way to revert back to the 24-hour format without changing the code? Any information you could provide on this issue would be greatly appreciated. Thank you for your assistance.
0
0
177
1w
Mixing capabilities from different Pass Types
I'm looking into developing a Pass that drills down into other screens and would add buttons below a pass. I'm finding it hard to get any information on these capabilities. Does anyone have any resources that might help. Essentially, mixing features between different pass types (payment cards, generic passes, etc).
0
0
116
1w
Extremely long UITextView text causing performing issues
I have an extremely (et cetera ad infinitum) textview that is lagging when typing (presumably) because of the text. Not sure what textkit is doing under the hood but if I were building it from scratch I wouldn't need to do any calc when the user is typing. I could just would design it so each new line is like's it's own textfield so to speak. But clearly that isn't the case. Any suggestions / can someone at Apple on the textkit team reach out ? (I interviewed with someone from that team before so I know it exists lol)
0
0
120
2w
UIDocumentViewController and multiple windows
I'm trying to migrate my document-based app to UIDocumentViewController so that it can take advantage of the new launch experience in iOS 18. Unfortunately, UIDocumentViewController closes the UIDocument when the document is set to nil or the controller is deallocated. This means you can't have the same document in more than one scene. Is there any way to prevent UIDocumentViewController from closing the document? -Steve
1
0
179
2w
scene(_:continue:) not invoked
Hi all, I recently migrated our app from AppDelegate to SceneDelegate in order to make it available on visionOS. So far it is working, but I have a problem with Universal links not being invoked. I implemented: func scene(_ scene: UIScene, continue userActivity: NSUserActivity) in my Scene Delegate, but it doesn't get invoked after the system opens the app. This only happens, if the app is running in the background. If the app is not running and is launched by the OS, I receive the URL as expected in: func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) If I also implement: func scene(_ scene: UIScene, willContinueUserActivityWithType userActivityType: String) it will be invoked by the OS, but after willContinueUserActivityWithType was called, neither: func scene(_ scene: UIScene, didFailToContinueUserActivityWithType userActivityType: String, error: any Error) nor: func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) are being invoked by the OS. I made a simple Barebones project with the same Bundle ID and the same Entitlements and there: func scene(_ scene: UIScene, continue userActivity: NSUserActivity) is being invoked as expected, upon tapping on the Universal Link in another app. What might be the difference between the two projects causing this behaviour? It is a rather big and old app, so it is difficult for me to compare the simple example project to the real project. Does anybody know, where I could start to debug? Many thanks in advance!
1
0
164
2w
Show animation images using UIImageView
We want to animate the images using animationImages propery of UIImageView in our app. There are 45 heif images with dimensions of 1668x2388. Below is the code i am using to animate images. let imageViewAnimation = UIImageView() imgViewAnimation.animationImages = images imgViewAnimation.animationDuration = 5.0 imgViewAnimation.animationRepeatCount = 1 imgViewAnimation.startAnimating() Timer.scheduledTimer(withTimeInterval: 5.0 + 0.5, repeats: false) { _ in DispatchQueue.main.async { self.showAlert() } } The issue i am facing is, it takes more than 5.0 seconds (animationDuration) to display all the images. Alert is shown before all the images are shown. We face this issue only for few sets of images. For some other sets, it is working fine. Is this issue due to heif images used, or due to memory and CPU load of using large number of images.
2
0
202
2w