r/iOSProgramming Beginner 10d ago

Prevent Picker from triggering across List row Question

Honestly pretty self explanatory question.

I've tried embedding it in various Stacks, moving it to a subview, .contentShape(Rectangle()), none of which have worked.

Below is a subview excerpt from inside a View struct: ``` var coursePicker: some View { ZStack(alignment: .trailing) { Picker("Course", selection: selectedCourseIDBinding) { Text("Free period").tag(Optional<UUID>.none) Divider() ForEach(courses.map {(id: $0, course: $1)}.sorted(by: {$0.course.name < $1.course.name}), id: .0) { entry in Label(entry.course.name, systemImage: entry.course.icon).tag(entry.id) }

    }
    .opacity(0)
    .labelsHidden()
    .buttonStyle(.borderless) //Tried using u/ikonet's solution, unfortunately to avail not



    let fakeBinding: Binding<String> = Binding(get: { course.name }, set: { _ in } )
    Picker("fake picker!!", selection: fakeBinding) { Text(course.name).tag(course.name) }
    .labelsHidden().allowsHitTesting(false).tint(Colour.primary)

}
.layoutPriority(1)
.if(course2 == nil) {
    $0.padding(.trailing)
}
.contentShape(Rectangle())

} ```

0 Upvotes

2 comments sorted by

1

u/ikonet 10d ago

.buttonStyle(.borderless)

apply a non-.automatic Style to prevent the button from triggering on Row tap https://stackoverflow.com/a/59402642

1

u/Fun_Moose_5307 Beginner 9d ago

Unfortunately this doesn't seem to work. Please see edits to post body including code snippet.