Hey there,
Link to the sample project: https://github.com/dev-loic/AppleSampleScrolling
Context
We are working on creating a feed of posts in SwiftUI. So far, we have successfully implemented a classic feed that opens from the top, with bottom pagination — a standard use case.
Our goal, however, is to allow the feed to open from any post, not just the first one.
For example, we would like to open the feed directly at the 3rd post and then trigger a network call to load elements both above and below it.
Our main focus here is on preserving the scroll position while opening the screen and waiting for the network call to complete.
To illustrate the issue, I created a sample project (attached) with two screens:
MainView, which contains buttons to open the feed in different states.
ScrollingView, which initially shows a single element, simulates a 3-second network call, and then populates with new data depending on which button was tapped.
I am currently using Xcode 26 beta 6, but I can also reproduce this issue on Xcode 16.3.
Tests on sample project
I click on a button and just wait the 3 seconds for the call.
In this scenario, I expect that the “focused item” stays at the exact same place on the screen. I also expect to see items below and above being added.
Simulator iPhone 16 / iOS 18.4 with itemsHeight = 100
position = 0, 1, 2, 3 ⇒ works as expected
position = 4, 5, 6, 7, 8, 9 ⇒ scroll is reset to the top and we loose the focused item
Simulator iPhone 16 / iOS 18.4 with itemsHeight = 500
position = 0, 1, 2, 3, 4 ⇒ works as expected
position = 5, 6, 7 ⇒ I have a glitch (the focused element moves on the screen) but the focused element is still visible
position = 8, 9 ⇒ scroll is reset to the top and we loose the focused item
Simulator iPhone 16 / iOS 26 with itemsHeight = 100 or 500
position = 0, 1, 2, 3, 4 ⇒ works as expected
position = 5, 6, 7, 8, 9 ⇒ I have a glitch (the focused element moves on the screen) but the focused element is still visible
Device iPhone 15 / iOS 26 with itemsHeight = 100
position = 0, 1, 2, 3, 4 ⇒ works as expected
position = 5, 6, 7, 8, 9 ⇒ I have a glitch (the focused element moves on the screen) but the focused element is still visible
Device iPhone 15 / iOS 26 with itemsHeight = 500
position = 0, 1, 2, 3 ⇒ works as expected
position = 4, 5, 6, 7, 8, 9 ⇒ I have a glitch (the focused element moves on the screen) but the focused element is still visible
Not any user interaction
Moreover, in this scenario, the user does not interact with the screen during the simulated network call. Regardless of the situation, if the ScrollView is in motion, its position always resets to the top. This behavior prevents us from implementing automatic pagination when scrolling upward, which is ultimately our goal.
My conclusion so far
As far as I know it seems not possible to have both keeping scroll possible and upward automatic pagination using a SwiftUI LazyVStack inside a ScrollView.
This appears to be standard behavior in messaging apps or other feed-based apps, and I’m wondering if I might be missing something.
Thank you in advance for any guidance you can provide on this topic.
Cheers
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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I am trying to learn to write swift. I am very proficient MS VB, which I have been using for almost 20 years. The Book I am learning from is:
SwiftUI for Masterminds. I have got to chapter 7 with no problem. The exercise I am having a problem with Listing 7-5. The error I am getting is:
Thread 1: Fatal error: No Observable object of type ApplicationData found. A View.environmentObject(_:) for ApplicationData may be missing as an ancestor of this view. I have spent the last 2 days rechecking my code. The MacBook I am using was purchased in May this year, is 16 in, M4 Max chip, 128 G ram.
Firstly I want to thank you for reading this post.
Secondly is there a better book to learn SwiftUI.
Regards
Terry Harrison
I'm noticing some weird glitches with my collection view headers on macOS Tahoe.
The sections headers are pinned to the visible region. I headers fade out when scrolling and are supposed to fade back in but sometimes they don't fade back in and the header remains but the header text doesn't come back (until I scroll again).
How can I turn off this scroll animation thingy?
I'm currently testing SwiftUI's WebKit by building a browsing application.
For the back navigation, I have the following code implemented:
if let item = webPage.backForwardList.backList.last {
webPage.load(item)
print(
"""
=====
backForwardList.backList:
\(webPage.backForwardList.backList)
---
backForwardList.currentItem:
\(webPage.backForwardList.currentItem)
---
backForwardList.forwardList:
\(webPage.backForwardList.forwardList)
=====
""".trimmingCharacters(in: .whitespacesAndNewlines)
)
}
When I look at the logs, it shows that whenever I navigate back, the currentItem is updated with the item, but the backList is appended with the previous currentItem, and the forwardList is always empty.
Am I implementing this incorrectly?
Thanks in advance!
Platform: iOS 26 RC / Xcode 26 RC
Component: UIKit - UITextField
Description:
When typing a Japanese character (or other IME input) as the first character in a UITextField and then losing focus (by pressing Enter or tapping elsewhere), the character is incorrectly duplicated. This issue only happens in iOS26 beta.
Steps to Reproduce:
Create a UITextField with shouldChangeCharactersIn delegate
Switch to Japanese keyboard
Type "あ" (or any hiragana character)
Press Enter or tap outside the text field
Observe the character count becomes 2 instead of 1
Expected Result:
Character count should remain 1
Actual Result:
Character is duplicated, count becomes 2
Sample Code:
func shouldChangeText(
in range: NSRange,
replacementText string: String,
maximumNumberOfCharacters: Int,
regexValidation: String? = nil) -> (String, Bool) {
guard let stringRange = Range(range, in: currentText) else {
return (currentText, false)
}
if let regex = regexValidation,
string != "", // delete key
!string.room.checkPattern(regex) {
return (currentText, false)
}
let changedText = currentText.replacingCharacters(in: stringRange, with: string)
let allowChange = changedText.utf16.count <= maximumNumberOfCharacters
print("=== stringRange: \(stringRange), currentText: \(currentText), replacementText: \(string) changedText: \(changedText), allowChange: \(allowChange) ===")
guard !allowChange else {
return (changedText, allowChange)
}
// Accept text deletion even if changedText count is more than maximumNumberCharacters
guard !string.isEmpty else {
return (changedText, true)
}
insert(text: string, maximumNumberOfCharacters: maximumNumberOfCharacters)
return (currentText, allowChange)
}
I’m creating a UITabBarController with a simple array of UITab instances. I’m setting the mode to .tabSideBar. How do I prevent editing? I don’t want the Edit button to appear at all. I’ve tried setting the tab controller’s customizableViewControllers property to both nil and an empty array but neither is preventing the Edit button from appearing. I scanned the various delegates and I don‘t see any relevant methods.
So far I’ve tested this on a simulated iPad running iPadOS 26 using Xcode 26 RC.
Hi!
I've encountered strange bug in iOS 26. The MultiDatePicker component exhibits unreliable behavior when attempting to deselect previously chosen dates. Users often need to tap a selected date multiple times (e.g., tap to deselect, tap to re-select, then tap again to deselect) for the UI to correctly register the deselection and update the displayed state.
This issue does not occur on iOS 18 or Xcode 26 previews, where MultiDatePicker functions as expected, allowing single-tap deselection. The bug only occurs on physical device or simulator. I can't lie, I have multidatepicker as crucial component in my larger app and can't really find a solution to this. Has anyone encountered this problem before?
Here is the code to replicate the issue:
import SwiftUI
struct ContentView: View {
@ State private var selectedDates: Set = []
var body: some View {
NavigationStack {
Form {
Section {
MultiDatePicker("Select Dates", selection: $selectedDates)
} header: {
Text("MultiDatePicker Bug Test")
}
Section {
Text("Selected Dates Count: (selectedDates.count)")
ForEach(Array(selectedDates).sorted(by: {
Calendar.current.date(from: $0)! < Calendar.current.date(from: $1)!
}), id: .self) { dateComponent in
if let date = Calendar.current.date(from: dateComponent) {
Text(date.formatted(date: .long, time: .omitted))
}
}
} header: {
Text("Current State of Selected Dates")
}
}
.navigationTitle("Date Picker Bug")
}
}
}
#Preview {
ContentView()
}
Hi everyone,
so I have a widget that is loading and showing images.
When changing my icons and widget to transparent or tinted on iOS 26 they just turn white or the tint color.
How can I mark images to preserve their appearance aka color?
The Fotos widget has (long press and its configuration) and option to tint them or preserve the color. I just can't figure out how it's done and what API to use.
Second, is there an API to learn which mode is currently being used to tweak other elements of the UI?
Thanks for any advice.
UIGlassEffect is giving a black rectangle, I tried setting the effect directly and in the animation block, but It does not make a difference. Replacing the effect with Blur sets the effect as expected. If there is another view inside the visualeffect.contentView it's not displayed as well. I tried setting the layout constraints as well as manually setting the frame of the VisualEffectView with no luck.
iOS 26.0 (23A341)
Topic:
UI Frameworks
SubTopic:
UIKit
If I try making a bitmap of a NSButton using the following code:
NSBitmapImageRep *rep = [button bitmapImageRepForCachingDisplayInRect:button.bounds];
[button cacheDisplayInRect:button.bounds toBitmapImageRep:rep];
NSData *tiffData = rep.TIFFRepresentation;
I get a blank image if the NSButton has its bezelStyle set to NSBezelStyleGlass.
If I change the bezel style to something else like NSBezelStyleFlexiblePush I do get an image
Crashlog-0916-071225.log
I have an app that crashes on OSX 26 only. I have a @StateObject which is an observer of the NSColorPanel.
When I call
let panel = NSColorPanel.shared
in init(), SwiftUI will crash - apparently with an update while view is being updated. See crash log.
I was able to work around it by adding
let _ = NSColorPanel.shared
in my AppDelegate before SwiftUI is initialized.
The exact code worked fine in all previous OSX versions.
The main problem here is that sometimes the snippet view has black text on a black background and it is unreadable.
To see what might be affecting this:
I tried checking the colorscheme enviroment value via @Environment(.colorScheme) in my view. This usually returns the correct device light/dark mode, however it returns incorrect after device restarts or app is updated. In order to correct this, user must toggle light/dark mode in device settings.
I also tried checking UITraitCollection.current.userInterfaceStyle in the perform() function of my AppIntent. This also usually returns the correct value, but does not after user toggles light/dark mode in device settings. In order to correct this, user must open the app.
The idea with checking these variables was that if one always returned the correct mode, I could set the text to the correct color instead of using .primary. Neither value seems to be 100% accurate and they fail in opposite situations.
Color.primary seems to align with the colorscheme environment variable. When we get the wrong value here (not cooresponding to the set device value), we will see something like black text on black background. Our returned view has no background set, so it matches the containing view. Colorscheme will say that the device is in lightmode when it is in darkmode, so although we have the correct background color, Color.primary is incorrect and the text is unreadable/hard to read.
Is there a solution that will never show unreadable text color besides forcing the view to have a specific colored background and specific colored text?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Previously I was able to "snapshot" view that were not part of any window hierarchy using the following:
NSImage *buttonImage = [NSImage imageWithSystemSymbolName:@"49.circle.fill" accessibilityDescription:nil];
NSButton *aButton = [NSButton buttonWithImage:buttonImage target:nil action:nil];
[aButton sizeToFit];
NSBitmapImageRep *rep = [aButton bitmapImageRepForCachingDisplayInRect:aButton.bounds];
if (rep == nil) {
NSLog(@"Failed to get bitmap image rep.");
return;
}
[aButton cacheDisplayInRect:aButton.bounds toBitmapImageRep:rep];
NSData *tiffData = rep.TIFFRepresentation;
NSImage *snapShotOfImage = [[NSImage alloc]initWithData:tiffData];
Now on macOS Tahoe I get a non nil image, but the image is blank.
However if I add aButton NSWindow's view hiearchy just before the call to -cacheDisplayInRect:toBitmapImageRep: I do get a proper image.
Is this behavior intended or is this considered a bug? Is it documented anywhere that a view must be in a NSWindow for -cacheDisplayInRect:toBitmapImageRep: to work? Thanks
I have initialized a new SwiftUI project for iOS. I wrapped the default NavigationSplitView from SwiftData inside a TabView and ran into the following issue:
On an iPad (Air, 13 inch, iPadOs 26), the button to open/close the sidebar shifts downwards while opening or closing the sidebar. When the animation finishes, the button jumps back to the original position.
Here's the code I used inside my ContentView:
var body: some View {
TabView {
Tab("Kategorien", systemImage: "circle.fill") {
NavigationSplitView {
List {
ForEach(items) { item in
NavigationLink {
Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
} label: {
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
}
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
} detail: {
Text("Select an item")
}
}
Tab("Alle Bücher", systemImage: "circle.fill") {
Text("Alle Bücher")
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
I created a tableview with two cells and configured a left-swipe action for each cell.
When I swipe left, the cell displays normally.
When I swipe the cell back to its original position, the view displays normally.
When I quickly swipe right after the cell has been reset, the view displays noticeably abnormally.
Topic:
UI Frameworks
SubTopic:
UIKit
When disabling the opacity slider of color panels, my app crashes with unsatisfiable layout constraints. Feel free reproduce with a minimal test project: A macOS app based on the Xcode 26.0 template with only one line added to the ViewController's viewDidLoad() function:
NSColorPanel.shared.showsAlpha = false
The issue doesn't occur if this property is set to "true" or not set at all.
I just filed a corresponding bug report (FB20269686), although I don't expect any feedback from Apple ... as numerous issues I reported were never updated or commented at all (after migrating from RADARs).
Topic:
UI Frameworks
SubTopic:
AppKit
I have a UISplitView with a UINavigationBar where I on iPhone have an issue with a containing UITableView which is not directly placed under the NavigationBar. When the new effect in iOS 26 kicks in it also seems to affect to topmost UINavigationBar which I do not want. It's when the clear UINavigationBar directly over the UITableView and passes over a content that it needs to invert its title over, it does. However it also inverts everything (background + title) of another topmost uinavigationbar which I don't want. This is even opaque and have no reason to invert its colors.
Any ideas on how to disable this?
navigationItem.style = .editor
navigationItem.centerItemGroups = [editorNavigationHelper.iPadCenterItemGroup()]
navigationItem.rightBarButtonItems = editorNavigationHelper.rightBarButtonItems()
let documentProperties = UIDocumentProperties(url: document.fileURL)
if let itemProvider = NSItemProvider(contentsOf: document.fileURL) {
documentProperties.dragItemsProvider = { _ in
[UIDragItem(itemProvider: itemProvider)]
}
documentProperties.activityViewControllerProvider = {
UIActivityViewController(activityItems: [itemProvider], applicationActivities: nil)
}
}
navigationItem.title = if UIDevice.current.isIPhone {
document.localizedName.trimmedToMax(12, appendingDots: true, adjustForDots: true)
} else {
document.localizedName
}
navigationItem.documentProperties = documentProperties
navigationItem.titleMenuProvider = { [weak self] suggested in
guard let self else {
return UIMenu(children: [])
}
let custom = [
// ...
]
return UIMenu(children: suggested + custom)
}
let navAppearance = UINavigationBarAppearance()
navAppearance.configureWithOpaqueBackground()
navAppearance.backgroundColor = UIColor.systemBackground
navAppearance.titleTextAttributes = [.foregroundColor: UIColor.label]
if let navBar = navigationController?.navigationBar {
navBar.standardAppearance = navAppearance
navBar.scrollEdgeAppearance = navAppearance
navBar.compactAppearance = navAppearance
navBar.isTranslucent = false
navBar.backgroundColor = .systemBackground
}
Topic:
UI Frameworks
SubTopic:
UIKit
Looking to see if anyone has experienced this issue, and is aware of any workarounds.
With an app migrating towards SwiftUI Views but still using UIKit for primary navigation, my app makes use of UIHostingController to push SwiftUI Views onto a UINavigationController stack in a lot of areas. With iOS 26, I notice that SwiftUI's Menu view really struggles to present when contained in a UIHostingController. An error is logged to the console on presentation, and depending on the UI, the Menu won't present inside of it's container, or will jump around the screen.
The bug, it seems is based in a private class UIReparentingView and I am curious if anyone has found a work around for this issue. The error reported is:
Adding '_UIReparentingView' as a subview of UIHostingController.view is not supported and may result in a broken view hierarchy. Add your view above UIHostingController.view in a common superview or insert it into your SwiftUI content in a UIViewRepresentable instead.
The simplest way to see this issue is to create a new storyboard based project. From the ViewController present a UIHostingController with a SwiftUI view that has a Menu and then simply tap to open the Menu. Thanks for any input!
Hello Developer Support,
I have the following code and the following crash. How can the swift data model unable to decode and yet able to display the decoded value at the same time?!
What's missing here?
CODE:
@Model
final class DisplayCache {
init(point: MKMapPoint) {
self.point = point
}
var point: MKMapPoint
}
CRASH
SwiftData/ModelCoders.swift:1069: Fatal error: Unable to decode this value MKMapPoint(x: 74358466.66307731, y: 97927933.41833577)
After updating to iPad OS 26, when moving around the app, I can not see the back button, title, and the right menu button on the navigation bar unless I scroll down, then everything is fine.
Any advice ?
Thanks