釣魚術
swift
原來是被遺忘的刪除功能,少了這個功能,就沒辦法刪除陳永仁的資料...
locationLoader.locationData
中移除資料HStack { // 刪除釣點
Spacer()
Button(action: delSecretLocation) {
Label("", systemImage: "bin.xmark.fill")
.labelStyle(.iconOnly)
.frame(width: 40, height:40)
.foregroundColor(.white)
.background(Color.red)
.cornerRadius(15)
.padding(10)
}
}
action: delSecretLocation
這個函式,還沒實作,所以要先做一個 func delSecretLocation 在這個 View 裏。VStack {
Text(boxTitle)
.font(.title2)
.fontWeight(.semibold)
ScrollView(.vertical) {
LazyVStack {
ForEach(Array(self.locationLoader.encodeCoordinate().enumerated()), id: \.element) { index, item in
HStack {
Text(item.name)
.frame(alignment: .leading)
.font(.headline)
Spacer()
Button {
delSingleLocation(pin: item, index: index)
} label: {
Label("", systemImage: "xmark.bin.circle")
.labelStyle(.iconOnly)
.frame(width: 20, height:20)
.foregroundColor(.white)
.cornerRadius(5)
.padding(10)
}
}
}
}
}
}
.padding()
.frame(width: screenSize.width * 0.6, height: screenSize.height * 0.4)
.background(Color.indigo)
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
.shadow(color: Color.gray, radius: 15, x: -1, y: -1)
.offset(y: alertIsPresented ? screenSize.height * 0.1 : screenSize.height)
func delSecretLocation() {
self.delLocationListIsPresented.toggle()
}
delLocationListIsPresented
布林變數的狀態。DelPinAlert(alertIsPresented: $delLocationListIsPresented,
locationLoader: $myLocationLoader)
func delSingleLocation(pin: FishPinAnnotation, index: Int) {
self.locationLoader.locationData.remove(at: index)
self.locationLoader.saveAndReloadLocation()
self.alertIsPresented.toggle()
}