APP有一個UI是輸入數字的TextField,每輸入一個數字會自動跳至下一個TextField,總共有6個Textfield,但是用戶輸入時,畫面顯示的數字會自動縮小,並取不到Textfield的值,非常奇怪!!
UIKit
RSS for tagConstruct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.
Post
Replies
Boosts
Views
Activity
I'm getting a crash wherever I've used the Collection view in my app with this exception:
Unhandled managed exception: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view:
It not built with native Swift or Xcode, instead it's a .Net MAUI app for iOS and it's crashing only on iOS 18+ and working absolutely fine on all other versions below iOS 18. I've not used any dequeuing of cells or any such code as it is not a native code, it's C# code and I'm just using template selector for designing different cells of collection view, so I'm not getting any fix for this exception as how to fix this dequeuing problem when I don't even have any such native code. Has anyone fixed this issue or find a solution for it yet?
For a UIKit app based on scenes (UIScene), is it safe to reference UserDefaults in code that is executed from UIApplicationDelegate/application(_: didFinishLaunchingWithOptions:) ?
I've read that in iOS 15, there were undocumented scenarios involving app prewarming that would cause UserDefaults reads to fail within a window of time after device reboots, as described at https://christianselig.com/2024/10/beware-userdefaults/
The failure mode is that an app would be released, and months later, a small fraction of users would report failures consistent with UserDefaults reads unexpectedly returning nil, causing a loss of data. The user experience is bad, and debugging this behavior is then challenging because of how rarely it occurs.
Apple's https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app/about_the_app_launch_sequence#3894431 seems to suggest that prewarming only executes an app "up until, but not including when main() calls UIApplicationMain(_:_:_:_:), but https://stackoverflow.com/questions/71025205/ios-15-prewarming-causing-appwilllaunch-method-when-prewarm-is-done documents that UIApplicationDelegate/application(_: didFinishLaunchingWithOptions:) has in fact been observed executing during app prewarming in scene-based apps.
So, my question: In an app based on scenes, if I'd like to reference UserDefaults within UIApplicationDelegate/application(_: didFinishLaunchingWithOptions:), when is it safe to do this?
I'm guessing the answer is one of these:
Never.
Only in apps that don't support scenes.
Only in iOS 16 or later.
Only in IOS 17 or later.
Is it guaranteed safe to reference UserDefaults in UIWindowSceneDelegate/scene(_:willConnectTo:options:) or later?
Is there documentation from Apple regarding this issue?
Thank you.
There was a crash during the creation of picture-in-picture in iOS 18. No problems were found after reviewing the code.
Please take a look at the possible reasons for the code crash here and how the business code should be protected
21 libsystem_kernel.dylib 0x1dac4ec20 abort_with_payload_wrapper_internal + 104
22 libsystem_kernel.dylib 0x1dac4ebb8 abort_with_reason + 32
23 libobjc.A.dylib 0x1880ffea0 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 116
24 libobjc.A.dylib 0x1880ffe2c _objc_fatal(char const*, ...) + 32
25 libobjc.A.dylib 0x1880ff040 weak_register_no_lock + 396
26 libobjc.A.dylib 0x1880fec50 objc_storeWeak + 472
27 AVKit 0x1b7a904e4 -[AVObservationController initWithOwner:] + 164
28 AVKit 0x1b7ab1d90 -[AVPictureInPictureController _commonInitWithSource:] + 104
29 AVKit 0x1b7b6cc14 -[AVPictureInPictureController initWithContentSource:] + 184
30 AVKit 0x1b7b6ccd8 -[AVPictureInPictureController initWithPlayerLayer:] + 84
I am creating an application using PKCanvasview.
One function of that app is the ability to trace and retrieve a UITextView that has been addSubviewed to a PKCanvasView.
We have confirmed that this functionality works correctly in the simulator and on the actual device on IOS 17.4.
This feature did not work correctly on the IOS18 simulator and the actual device.
Is this a bug?
And if it is normal behavior, is there an alternative?
My app supports only iPhone mode, and when it runs on an iPad device, it normally displays compatible iPhone mode;
But when compatibility mode is displayed normally, everything is fine in the UI.
But my code as long as you use the AVPictureInPictureController, open the picture in picture, can lead to code for [UIScreen mainScreen] bounds will change, become the real width and height of the equipment, so the UI disorder;
Problems arise when our code is laid out with [UIScreen mainScreen] bounds.
Like this:
This was normal in iOS16 and iOS17, but suddenly it happened in iOS18
How should my application be compatible with this?
I've got a UIKit app with a collapsible trailing-edge child view controller, implemented sort of like UISplitViewController but it's got a bunch of custom behavior - moving to the bottom edge in portrait orientation, etc. It exposes a couple of different app functions via a UITabBar on the bottom edge on iOS.
When I run the app on visionOS, that tab bar transforms to a leading-edge ornament. This would be great, but that means it tries to overlap the trailing-edge content of its parent view controller, which isn't ideal.
Is there a way to get the tab bar to lay out on the trailling edge of the child view controller? Or can I create a custom ornament that has the same auto-expand behavior as the tab bar, where it shows a vertical column of icons that expands to show titles when you're gazing at it?
I am trying to build a UICollectionView where the rows expand / collapse (for example, where the row only has a title initially, but when tapped expands to show a text view). I'm aware I can use UIContentConfiguration to swap a SwiftUI view for the cell's contentView, but I'm trying to do this in UIKit for configurability.
I have watched WWDC 22, 10068: What's new in UIKit, which made this sound easy...
I am using UICollectionLayoutListConfiguration for the UICollectionViewLayout.
When a cell is tapped, I update the subviews' constraints to the "expanded" state, but this just causes the subviews to expand beyond the cell height. All subviews are on cell.contentView. Calling layoutIfNeeded, invalidateIntrinsicContentSize, on cell doesn't change the cell height.
I assumed all I would need to do is set collectionView.selfSizingInvalidation = .enabledIncludingConstraints, but is overriding intrinsicContentSize of the cell the only way to accomplish this?
I've got a UIKit app and I want to add some buttons in a top-edge window ornament. I'm looking at the WWDC23 talk Meet UIKit for Spatial Computing, and it does exactly what I think I want to do:
extension EditorViewController {
func showEditingControlsOrnament() {
let ornament = UIHostingOrnament(sceneAlignment: .bottom, contentAlignment: .center) {
EditingControlsView(model: controlsViewModel)
.glassBackgroundEffect()
}
self.ornaments = [ornament]
editorView.style = .edgeToEdge
}
}
But the thing I really want to know is what is in EditingControlsView. Is it a toolbar? How do you make a toolbar in SwiftUI without something to attach the .toolbar modifier to?
My app supports only iPhone mode, and when it runs on an iPad device, it normally displays compatible iPhone mode.
But my code as long as you use the AVPictureInPictureController, open the picture in picture, will lead to get [UIScreen mainScreen] bounds became the real width and height, so the UI disorder;
How should my application be compatible with this?
How to make the tab display at the bottom on an iOS 18 iPad? Currently, the bottom of the app is blank, as shown in the following picture
I'm developing Locked Camera Capture Extension.
I noticed UIViewController's view.frame size on extension is smaller than app's one. It seems extension's View.frame is same as safe-area's frame.
WWDC24 session Build a great Lock Screen camera capture experience doesn't mention this issue. It looks like bug for me or is it intended specification to avoid complexity for users ?
New in iOS 17.5 is UIImpactFeedbackGenerator/impactOccurred(at:), which generates haptic feedback at a specific screen location.
https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator/4403143-impactoccurred
Which devices support this?
How does this work if the Taptic Engine has a fixed physical location?
To set up iOS 18 widget tint mode without any modifications, follow the steps below.
I hope this helps many people.
You just need to add one line.
.containerBackgroundRemovable(false)
ex)
struct create_view: Widget {
let kind: String = "CalendarWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
calendar_widgetEntryView(entry: entry)
}
.supportedFamilies([.systemLarge])
.containerBackgroundRemovable(false)
.contentMarginsDisabledIfAvailable()
}
}
Before:
After :
I'm developing LockedCameraCapture extension.
My extension can capture photo, save to system photo library and load from system photo library. That's pretty nice extension.
I want to fix interface orientation to portrait for particular screen(capture screen). But I want some other screen to landscape orientation(photo viewing screen).
So, I'm using "supportedInterfaceOrientations" property and "setNeedsUpdateOfSupportedInterfaceOrientations" method for interface orientation flexibility.
This code implies the screen only supports portrait orientation.
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
.portrait
}
And I call this code to enable orientation setting.
// UIViewController # viewDidLoad
setNeedsUpdateOfSupportedInterfaceOrientations()
My App work as expected, but my CaptureExtension doesn't work.
My extension's capture screen can rotate Landscape and that's not intended behavior.
Hi! I'm developing a custom keyboard and my user reported that they can't switch to my keyboard while using external original iPad keyboard.
Unfortunately, I can't test it on a real device and I can't find a way to test it using a simulator.
My questions:
Is it possible to simulate this case on a simulator?
Is it possible to temporarily show a custom keyboard while using an external keyboard on iPad? I saw in the photos that this keyboard has a globe button, but my user told me that nothing happens when they hold or press hit.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Dequeued view: <Pezzano_Enterprises.BannerImageCollectionViewCell: 0x103af8370; baseClass = UICollectionViewCell; frame = (880 0; 440 130); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x6000003980a0>>; Collection view: <UICollectionView: 0x106030c00; frame = (0 0; 440 130); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600000de0240>; backgroundColor = <UIDynamicSystemColor: 0x6000017b0500; name = systemBackgroundColor>; layer = <CALayer: 0x600000337fe0>; contentOffset: {205.66666666666666, 0}; contentSize: {1320, 130}; adjustedContentInset: {0, 0, 0, 0}; layout: <UICollectionViewFlowLayout: 0x103b35720>; dataSource: <Pezzano_Enterprises.BannerTableViewCell: 0x10605d000; baseClass = UITableViewCell; frame = (0 0; 440 130); autoresize = W; layer = <CALayer: 0x600000336900>>>'
I have an app that is pretty simple and allows information to be collected when offline. The app works perfectly while online where users can type into textfields. However when cellular and WiFi is disabled, tapping into the textfield displays the on-screen keyboard. As soon as this appears, the app enters a system hang and no typing or any user interaction is possible.
Upon profiling, it appears that this has to do with an infinite loop with the keyboard detecting a change in the network for dictation and then trying to load an image asset, presumably the dictation button. The keyboard will not contain this button either. This is on a regular UITextField with no delegate or special treatment. I have removed all "appearance" in the app and that makes no difference.
This seems to be a major bug in iOS 17 and higher. It continues to fail on iOS 18+ as well as new versions of Xcode, updated SDKs, etc.
I can do this in other apps I've developed without issue so I'm assuming there's something in the app that is interfering somehow with the dictation network connectivity in the keyboard. Either way, an app interfering with the keyboard function still seems like a possible flaw in the operating system.
There are also multiple warnings displayed in the console in Xcode about AFPreferences unable to resolve system language too. This fills up the console very quickly because of the looping nature of this asset layout issue. Because this is never completing and getting locked up, you'll notice that the dictation button does not appear in the lower right corner. However the cursor continues to blink but the user interface is non-responsive.
Any ideas what would be interfering with the drawing of the keyboard like this?
You used to be able to use the "User Defined Runtime Attributes" section in Interface Builder to add attributes such as layer.borderColor, layer.borderWidth, layer.cornerRadius, etc. I can still enter these values, but they don't do anything. What happened?
I can still set them via code and then they work, but it's much more convenient to be able to do it in interface builder.
When I create a modal segue to a navigation controller in a storyboard, the navigation bar buttons appear correctly. But when trying to recreate this programmatically, no buttons appear:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .infoLight, primaryAction: UIAction(handler: { _ in
self.present(UINavigationController(rootViewController: ModalViewController()), animated: true)
}))
button.frame.origin = CGPoint(x: 100, y: 100)
view.addSubview(button)
}
}
class ModalViewController: UIViewController {
override func loadView() {
let button = UIBarButtonItem(title: "button")
button.primaryAction = UIAction(handler: { action in
})
button.style = .done
navigationItem.title = "title"
navigationItem.rightBarButtonItem = button
view = UITableView()
}
}
What am I doing wrong?