Post

Replies

Boosts

Views

Activity

Migrating selection-based navigation inside ForEach
Below is my deprecated solution to immediately go the the destination view when creating a new item with the "plus"-Button. I don't get how to migrate the deprecated 'init(destination:tag:selection:label:)' to the new NavigationStack or NavigationSplitView Any help appreciated. struct ItemList: View { @StateObject private var itemStore = ItemStore() @State private var indexItem: Int? var body: some View { NavigationView { List { let itemStoreZip = zip(itemStore.allItems.indices, itemStore.allItems) ForEach(Array(itemStoreZip), id: \.0) {i, item in let itemBind = $itemStore.allItems[i] NavigationLink(destination: ItemDetail(item: itemBind), tag: i, selection: $indexItem) { ItemRow(item: item) } } .onDelete { indexSet in itemStore.removeItem(indexSet: indexSet) } .onMove { indices, newOffset in itemStore.moveItem(source: indices, to: newOffset) } } .navigationTitle("Homepwner") .toolbar { ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) { EditButton() } ToolbarItem(placement: ToolbarItemPlacement.navigationBarLeading) { Button { (indexItem,_) = itemStore.newItem() } label: { Image(systemName: "plus") } } } } } }
2
0
985
Jan ’23
Migrating selection-based navigation inside ForEach
Below is my deprecated solution to immediately go the the destination view when creating a new item with the "plus"-Button. I don't get how to migrate the deprecated 'init(destination:tag:selection:label:)' to the new NavigationStack or NavigationSplitView Any help appreciated. struct ItemList: View { @StateObject private var itemStore = ItemStore() @State private var indexItem: Int? var body: some View { NavigationView { List { let itemStoreZip = zip(itemStore.allItems.indices, itemStore.allItems) ForEach(Array(itemStoreZip), id: \.0) {i, item in let itemBind = $itemStore.allItems[i] NavigationLink(destination: ItemDetail(item: itemBind), tag: i, selection: $indexItem) { ItemRow(item: item) } } .onDelete { indexSet in itemStore.removeItem(indexSet: indexSet) } .onMove { indices, newOffset in itemStore.moveItem(source: indices, to: newOffset) } } .navigationTitle("Homepwner") .toolbar { ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing) { EditButton() } ToolbarItem(placement: ToolbarItemPlacement.navigationBarLeading) { Button { (indexItem,_) = itemStore.newItem() } label: { Image(systemName: "plus") } } } } } }
Replies
2
Boosts
0
Views
985
Activity
Jan ’23