I have a screen with a list that one side is empty when use on a iPad. as seen in the image or mac is empty .
The code below
import SwiftUI
// How to declare an array
var stockalertdtas :[StockAlertDta] = [testStockAlertData,testStockAlertData]
struct StockAlertListUIView: View {
@StateObject var viewModel = StockAlertListUIViewModel()
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@State var firstSelection: StockAlertDta?
var body: some View {
NavigationView{
ZStack{
//how to select the first value in the f
List() {
ForEach(viewModel.userStockAlertDtas, id:\.self){
stockalert in
NavigationLink(destination: StockDetailUIView(stockAlert: stockalert), tag: stockalert, selection: self.$firstSelection) {
StockAlertRow(stockAlertDta: stockalert)
}
}.onDelete(perform: { IndexSet in
IndexSet.forEach{ array_id in
viewModel.deleteItem(atOffsets: array_id)
}
viewModel.userStockAlertDtas.remove(atOffsets: IndexSet)
})
}
if viewModel.userStockAlertDtas.isEmpty {
EmptyState(imageName: "empty-order", message: "You have not created any Alerts\nPlease create some alerts")
}
}.navigationTitle("Alerts")
}.onAppear{
viewModel.getAllStockAlert()
let stockAlertHelper = StockAlertHelper()
stockAlertHelper.hasTargetsBeenReach()
viewModel.getInstruments()
if self.horizontalSizeClass == .regular {
self.firstSelection = viewModel.userStockAlertDtas.first
}
}
}
}
struct StockAlertListUIView_Previews: PreviewProvider {
static var previews: some View {
StockAlertListUIView()
}
}
How do i solve this issue?