Search results for

column

2,061 results found

Post

Replies

Boosts

Views

Activity

NavigationSplitView resetting when app enters background
I've been trying to build an app using NavigationSplitView and SwiftUI on iOS 16. I noticed that as soon almost as the app enters the background (sometimes I have to wait a few seconds before immediately reopening the app) the contents of the NavigationSplitView are reset. This behavior differs from a NavigationStack using essentially the same path and app structure. I'm wondering if anyone has any idea why this happens? I did a little investigation and can say I've noticed a few things If using a List with a selection item specified, the selection item is set to nil when the app enters the background. For NavigationSplitView this typically will reset the downstream Detail or Content view since the value is lost If using a List without the selection parameter specified this effect is mitigated but the view still is reset and things like scroll position are wiped despite no content changing. Self._printChanges() indicates the view is unchanged despite being reset to its initial state. Using Apple's own WWDC sa
2
0
1.4k
Jul ’23
Display a LazyVGrid with Sections
I am trying to render a list of entities that are split into sections (think CoreData NSFetchedResultsSectionInfo). This my solution, however it renders poorly. The ScrollView is far too long, scrolling is not fluid and may freeze. struct SectionsGridView: View { let results: Sections let columns = [ GridItem(.adaptive(minimum: .cellSize)) ] var body: some View { ScrollView { LazyVGrid(columns: columns, spacing: .gridSpacing, pinnedViews: .sectionHeaders) { ForEach(results) { section in Section(header: Text(section.title?.uppercased() ?? error)) { ForEach(section) { item in GridCell().environmentObject(item) } } } } } } } private extension CGFloat { static let gridSpacing = 8.0 static let cellSize = 100.0 } I believe this solution (or very similar) used to be in the documentation. I have tried several ways of doing this, either I get the scrolling issue or pinnedViews won't pin.
1
0
2.7k
Jul ’23
Reply to Creating a dynamic 5X5 Matrix
import SwiftUI import UIKit class MatrixViewController: UIViewController { let matrix = [ [A5, B5, C5, D5, E5], [A4, B4, C4, D4, E4], [A3, B3, C3, D3, E3], [A2, B2, C2, D2, E2], [A1, B1, C1, D1, E1], ] let matrixLabelSize: CGFloat = 30.0 override func viewDidLoad() { super.viewDidLoad() setupMatrixView() } func setupMatrixView() { let matrixView = UIView() matrixView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(matrixView) let matrixViewWidth = CGFloat(matrix[0].count) * matrixLabelSize let matrixViewHeight = CGFloat(matrix.count) * matrixLabelSize NSLayoutConstraint.activate([ matrixView.centerXAnchor.constraint(equalTo: view.centerXAnchor), matrixView.centerYAnchor.constraint(equalTo: view.centerYAnchor), matrixView.widthAnchor.constraint(equalToConstant: matrixViewWidth), matrixView.heightAnchor.constraint(equalToConstant: matrixViewHeight) ]) var positionCounts: [String: Int] = [:] //counting the number of occurences - - - - - - this part for coordinate in coordinates { let row = coor
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’23
Reply to Creating a dynamic 5X5 Matrix
From what I've understood, it doesn't need to be 5 dimensional, but rather, 2 dimensional. The dimension in a matrix doesn't correspond to the number of rows and columns. In your case, two dimensions seems enough: one for the severity (from one to five), and one for the likelihood (1 to 5). You could therefore store data like so : Matrix[2][5] = 3 (which would mean that there are 3 questions that have a severity of 2 and a likelihood of 3). A good visual representation of the dimensions of a matrix would be the following. A one-dimensional matrix is just an array/list. A two dimensional array corresponds to an Excel/Numbers spreadsheet. And a three dimensional array could be use to store the coordinates of the cubes composing a Rubik's Cube, for example. Above 3, it's hard to have a visual representation. A 5-dimensional matrix would be suitable if you had 5 different sliders per question. Therefore, if you can represent your table in a spreadsheet, it means that two dimensions is enough. Let me know
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’23
LazyVGrid generating endless loop with remote image fetch
I'm having a very weird issue using LazyVGrid that I've been banging my head over now for weeks. I have a loop that runs over a filtered list of locations and prints out the image with the location name below which is drawn from CategoryItem. let columns = [GridItem(.adaptive(minimum: 150), alignment: .top)] ScrollView { LazyVGrid(columns: columns, spacing: 10) { ForEach(categoryFilter) { landmark in let _ = print(catFilter= (landmark)) NavigationLink { DetailView(landmark: landmark) } label: { CategoryItem(landmark: landmark) } .frame(height: 185) } } } I kept getting a blank screen and could see no way around it so I put a print inside the loop and noticed that it was just continually printing the content from categoryFilter in an endless loop. If I commented out just the LazyVGrid loop (leaving just the bare ForEach loop) it works. And if I comment out just the remote fetching of the image which in my case is KFImage(URL(string: imageURLString)) (which is inside CategoryItem) the
0
0
457
Jul ’23
Reply to Build Simulator crash
The code is very long so i hope this edit is sufficient to read. Where do you use relativeRiskPickerIndex31? - there are 31 questions in this part of the app,. each app has 2 sets of answers for users to choose from. #1 Slope Angle (they choose answer from picker one) and picker two in the relativeRiskPickerIndex.. basically there are from 1 until 31 risk picker indexes using this: let relativeRiskChoices = [Select, Negligible, Minor, Moderate, Significant, Major] let relativeRiskScores = [-,A, B, C, D, E] //the code above this line is from another swift file that just gets called to the file to the code below. The state var values are all zero. There is no error message inside the code lines but when I run the simulator and try to run and pick answers from the questions and answers inside the simulator, it Freezes and stops working. so i have to force quit it again to try to run it again. however, if i do not use the pickers and just directly try to export pdf, it works. The last time I tried this popped up
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’23
Issue inserting row in TabularData's DataFrame
I'm fairly new to Swift programming so I might be overlooking something, but I'm puzzled why the following code doesn't properly insert a row in a DataFrame. The goal is to move a row at a given index to a new index. I would normally: Copy the row that I want to move Remove the row from the original dataset Insert the copy to the new position The CSV I'm using is from Wikipedia: Year,Make,Model,Description,Price 1997,Ford,E350,ac, abs, moon,3000.00 1999,Chevy,Venture Extended Edition,,4900.00 1999,Chevy,Venture Extended Edition, Very Large,,5000.00 1996,Jeep,Grand Cherokee,MUST SELL! air, moon roof, loaded,4799.00 My code (Swift playground): import Foundation import TabularData let fileUrl = Bundle.main.url(forResource: data, withExtension: csv) let options = CSVReadingOptions(hasHeaderRow: true, delimiter: ,) var dataFrame = try! DataFrame(contentsOfCSVFile: fileUrl!, options: options) print(Original data) print(dataFrame) let rowToMove: Int = 2 let row = dataFrame.rows[rowToMove] print(Row to move) print(ro
4
0
1k
Jul ’23
FileManager Has Saved My Images - yet I cannot see / display them whenever I close and reopen the application.
So basically I can tell that the images are being saved by the system (it shows it on the debug terminal) however whenever I close, and then reopen the app the images firstly aren't there at all but also whenever I search the address name I saved them as... I have tried diagonsing the problem by changing UUID's, changing PNGs to JPGS - no matter what I do it does not show once the application has closed. I think it might have to do with how the image are .HEIF (apple's standard) but I don't have any concrete evidence to back this up. If anyone can help it would be greatly apperciated. import SwiftUI import MapKit import CoreLocation struct ContentView: View { @StateObject private var mapAPI = MapAPI() @State private var text = @State private var locationInfo: String = @State private var showLocationInfo = false @State private var imageUrls = [String]() // Array to store image URLs @State private var showImagePicker = false @State private var showCamera = false @State private var selectedImage: UIImage? @Sta
1
0
710
Jul ’23
FileManager Has Saved My Images - yet I cannot see / display them whenever I close and reopen the application.
So basically I can tell that the images are being saved by the system (it shows it on the debug terminal) however whenever I close, and then reopen the app the images firstly aren't there at all but also whenever I search the address name I saved them as... I have tried diagonsing the problem by changing UUID's, changing PNGs to JPGS - no matter what I do it does not show once the application has closed. I think it might have to do with how the image are .HEIF (apple's standard) but I don't have any concrete evidence to back this up. If anyone can help it would be greatly apperciated. import SwiftUI import MapKit import CoreLocation struct ContentView: View { @StateObject private var mapAPI = MapAPI() @State private var text = @State private var locationInfo: String = @State private var showLocationInfo = false @State private var imageUrls = [String]() // Array to store image URLs @State private var showImagePicker = false @State private var showCamera = false @State private var selectedImage: UIImage? @Sta
2
0
614
Jul ’23
Alert within Popover is clipped in height causing title to be hidden
When showing an Alert from within a Popover that has a fixed height, the newly presented Alert is in the same position but gets limited by the Popovers height causing the title of the Alert to be hidden. Is this intentional behavior or are Alerts not supported within Popovers and I'd have to pass it through to my main view? Code: // // DemoalertPopover.swift // ******** // // Created by Thilo on 26.06.2023. // import SwiftUI struct DemoAlertPopover: View { @Environment(.dismiss) var dismiss @State private var showDeleteConfirmation = false let dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateFormat = dd.MM.yyyy return formatter }() var body: some View { VStack(alignment: .leading, spacing: 0) { HStack { Text(Title).font(.extraLargeTitle).lineLimit(1) Spacer() Button(action: { dismiss() }) { Label(Close, systemImage: xmark).labelStyle(.iconOnly) } } HStack(alignment: .center) { Text(Content).font(.largeTitle) Text(Content2).foregroundStyle(.secondary) } LazyVGrid(columns:
2
0
831
Jun ’23
How to hide stacked navigation bars when using SwiftUI inspector in UISplitViewController secondary column
During WWDC Q&As I asked how I could add an inspector to my UIKit app that’s using UISplitViewController with a double column style featuring a sidebar and detail view controller. I initially tried a full-height inspector (by putting my split view controller into a SwiftUI view and applying the inspector on that, embedding that into a UIHostingController to be the rootViewController) but this caused a bunch of UI bugs (seemingly related to optimizations made for a size class that doesn’t match the actual appearance) and it doesn’t extend into the NSToolbar on Mac Catalyst anyways. I now want to try implementing the under-the-toolbar solution. An engineer said: For an under toolbar appearance, you should be able to use .inspector on the detail view controller (after wrapping it in a SwiftUI view), but you may have to do manual toolbar management here (hiding and showing) to make sure you don't end up with stacked toolbars/UINavigationBars I have indeed run into the problem with two navigation bars
0
0
1.2k
Jun ’23
This is my code for a Personal Project - the problem I'm facing is saving the images that the user has added - i run into to problem after problem so if anyone can help in saving the images under the encoded address so I can access that would be good
struct ImagePicker: UIViewControllerRepresentable { typealias UIViewControllerType = UIImagePickerController var sourceType: UIImagePickerController.SourceType var completionHandler: (UIImage?) -> Void func makeUIViewController(context: Context) -> UIImagePickerController { let imagePicker = UIImagePickerController() imagePicker.sourceType = sourceType imagePicker.delegate = context.coordinator return imagePicker } func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) { // No update needed } func makeCoordinator() -> Coordinator { Coordinator(completionHandler: completionHandler) } final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate { private let completionHandler: (UIImage?) -> Void init(completionHandler: @escaping (UIImage?) -> Void) { self.completionHandler = completionHandler } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey
0
0
503
Jun ’23
Full height SwiftUI inspector in Mac Catalyst app
I have a UIKit Mac Catalyst app, optimized for Mac idiom, with an NSToolbar manually added to the windowScene. Is it possible to implement a full-height inspector sidebar with this setup? It seems to always appear underneath the toolbar in my testing. Even if I remove my NSToolbar and let the system create a toolbar from a NavigationStack. It works on iOS - stretches all the way up the window splitting the app into two columns. var body: some View { NavigationStack { AnimalTable(state: $state) .inspector(isPresented: $state.inspectorPresented) { AnimalInspectorForm(animal: $state.binding()) } .toolbar { Button { state.inspectorPresented.toggle() } label: { Label(Toggle Inspector, systemImage: info.circle) } } } }
0
0
1k
Jun ’23
How do I disable a button while it has focus
I have a view that shows a table and 4 buttons. Each button allows the user to step forward and backwards through the data. Buttons are enabled and disabled based on where you are in the data. If you are less than 200 values to the end of the data for example, the Page Down - 200 button is disabled. Everything works fine if the mouse is used to run the code associated with each button. But in this case I think the buttons never get focus. Focus I think remains with the sidebar content item that brought up the table view (am using a navigation split view). If I tab over to the page down 200 button and use the space bar to run its associated code I get the error AttributeGraph: cycle detected through attribute 864480. I think the problem lies with attempting to disable the button while it has focus but am not 100% sure. I have tried to change the focus prior to disabling the button but I get the same error. I think there is some fundamental that I am missing. Below is my table view along with the page down 200
3
0
1.6k
Jun ’23
No audio on device speakers, works fine with headphones / airplay
hi I am having a issue with sound on a network video stream, the stream is loaded by a m3u,. during playback there is no audio from the device, however when using headphones / airplay audio works correctly. the other peculiar thing is the device simulator works fine. this maybe related to airplay working, but I don't know. this is the view handling the playback. Im not sure where the issue is. I can also play the videos fine when embedding the avplayer in its own view. but that looks messy when you have to dismiss a second window when closing the video. #if os(iOS) import SwiftUI import AVKit import MediaPlayer struct iOSVideoLibraryView: View { @ObservedObject var videoLibrary: VideoLibrary @State private var isPlayerDismissed = false let LiveStreams = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] let VODStreams = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] var body: some View { NavigationView { ScrollView { LazyVGrid(columns:
2
0
1.3k
Jun ’23