I have the problem that I want to add a button with "Toolbaritem". This should be placed as "Add" button on the top right. But unfortunately this button is not displayed.
import SwiftUI
import RealmSwift
struct HomeListItems: View {
@ObservedRealmObject var homeList: HomeList
@State private var isPresented: Bool = false
@State private var selectedItemIds: [ObjectId] = []
var body: some View {
VStack {
if homeList.items.isEmpty {
Text("Keine ToDo's gefunden")
}
List {
ForEach(homeList.items) { item in
NavigationLink {
AddToDoItems(homeList: homeList, itemToEdit: item)
} label: {
ItemCell(item: item, selected:
selectedItemIds.contains(item.id)) { selected in
if selected {
selectedItemIds.append(item.id)
if let indexToDelete = homeList.items.firstIndex(where: {
$0.id == item.id }) {
// delete the item
$homeList.items.remove(at: indexToDelete)
}
}
}
}
}
}
.navigationTitle(homeList.title)
}.toolbar{
Button {
//action
isPresented = true
} label: {
Image(systemName: "plus")
}}
.sheet(isPresented: $isPresented) {
AddToDoItems(homeList: homeList)
}
}
}
struct HomeListItems_Previews: PreviewProvider {
static var previews: some View {
HomeListItems(homeList: HomeList())
}
}