Hi there! can someone help me with this one: func resetMatrix() { matrix = Array(repeating: Array(repeating: 0, count: numberOfColumns), count: numberOfRows) let coordinates = [ (selectedRow1, selectedColumn1), (selectedRow2, selectedColumn2), (selectedRow3, selectedColumn3) ] for (row, column) in coordinates { matrix[row - 1][column - 1] += 1 } } i can't seem to make it work. i want it to work like this: If the chosen coordinate in Question 1 is (2,2), it will place the value 1 in the matrix coordinate (2,2). If the chosen coordinate in Question 2 is also (2,2), it will increment the value in the matrix coordinate (2,2) by 1, making it 2. Similarly, if the chosen coordinate in Question 3 is (2,2), it will increment the value in the matrix coordinate (2,2) by 1 again, making it 3. Thank you!
Search results for
column
2,078 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
https://drive.google.com/file/d/1GWV9MYs_X4HG0XT4_-wDPPHdWOFwsRJs/view?usp=sharing Hi, everyone! So, I am trying to create an app that is like a survey app. I am new to coding by the way (less than a month) I have this long-ass code that I am trying to work. Well, it is working except for one more part of the code. I've been trying to make it work for days now and I cannot seem to figure it out. I uploaded it in a google drive link above. This is what it is: If you try to run this code in Xcode, you can see a thing like this: The app works like this, users select the pickers beside the Criteria and Relative Risk. The scores will show as: Score: 2,4 (just a sample score) criteria = row relative risk = column what I want to happen is that this score will immediately translate as a coordinate in the risk matrix below. There are 21 sets of pickers for this part of the app. The coordinates can have more than 1 value. so if there are 3 scores that have the same coordinate, such coordinate in the matrix sho
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
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.
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:
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:
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
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:
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
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
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
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:
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
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
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) } } } }