UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Buttons not working inside List View

Forums > SwiftUI

I have a row in a list with some text and two buttons either side. However, I am unable to press both buttons. It seems that having both buttons there doesn't work. I have created a simple example of the problem I am experiencing below. Just copy and paste the code and try for yourself. Changing the List to a VStack solves the issue, but I would like it in a list row as the rest of the screen content is a List.

import SwiftUI

struct ButtonTest: View {
    @State private var number = 0

    var body: some View {
        List {
            HStack{
                Button("Decrease") {
                    number -= 1
                }
                Spacer()
                Text("Text")
                Spacer()
                Button("Increase") {
                    number += 1
                }
            }
            Text("Number: \(number)")
        }
    }
}

Many thanks for any help!

2      

Yes, but you can set the button style on your List to something different. .buttonStyle(BorderlessButtonStyle())

2      

Works like a treat! Thank you.🙂

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.