我正在使用这个 EditNotesView,当我在 6 个月前对其进行编码时工作正常,但现在当我点击TextEditor
键盘时,它会出现,但TextEditor
. 如果我再次点击TextEditor
然后光标出现,我可以输入注释并保存。我也在控制台中收到此错误,我认为这是相关的?
完整的控制台错误:
2021-07-26 17:50:50.679871-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.679947-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.679972-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.679990-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.680006-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.680120-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.680146-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.680165-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.680182-0400 newFitnessApp[510:22218] [Assert] View <(null):0x0> does not conform to UITextInput protocol
2021-07-26 17:50:50.766468-0400 newFitnessApp[510:22218] [Snapshotting] Snapshotting a view (0x15268e680, _UIReplicantView) that has not been rendered at least once requires afterScreenUpdates:YES.
struct EditNotesView: View {
@Binding var notes: String
//@State private var notes: String = "type notes here"
@Binding var isShowingSheet: Bool
@EnvironmentObject var dataStore: DataStore
@Environment(\.colorScheme) var colorScheme
@ObservedObject var workoutDetailViewModel: WorkoutDetailViewModel
var body: some View {
VStack {
HStack {
Button("Cancel") {
isShowingSheet = false
}
.padding([.top, .leading])
.foregroundColor(Color.blue)
Spacer()
Button("Save") {
if let unwrappedHKWorkout = workoutDetailViewModel.fullyLoadedWorkout?.hkWorkout {
print("NOW WE WILL SAVE")
workoutDetailViewModel.updateMetadataAndSaveWorkout(workoutToBeUpdated: unwrappedHKWorkout, updateType: .notes(notes)) { (updatedWorkout) in
}
}
isShowingSheet = false
}
.padding([.top, .trailing])
.foregroundColor(Color.red)
}
HStack {
TextEditor(text: $notes)
.font(.body)
.if(notes == "type notes here") { $0.foregroundColor(Color.gray) } //This is a hack until TextEditor has a placeholder option
.padding()
//This is a hack until TextEditor has a placeholder option
.onTapGesture {
if notes == "type notes here" {
self.notes = ""
}
}
}
}
.onAppear {
if let unwrappedNotes = workoutDetailViewModel.fullyLoadedWorkout?.trackerMetadata.notes {
notes = unwrappedNotes
} else {
notes = "type notes here"
}
}
}
}
//This function is used so that TextEditor can take an optional string. If it gets updated in SwiftUI we can delete it
func ??<T>(lhs: Binding<Optional<T>>, rhs: T) -> Binding<T> {
Binding(
get: { lhs.wrappedValue ?? rhs },
set: { lhs.wrappedValue = $0 }
)
}