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

SOLVED: Form's Button in childView does not seems to be working

Forums > SwiftUI

Hi Guys,

I have a Button() inside a form from a child view (as described it the code below). And it does not seems to be working ( using .onTapGesture works... but that not cool)

Have any of you encountered this proble before ? is there a better solution than onTapGesture ?

Thanks

Tim

PrimaryView{
VStack{
    if self.mode?.wrappedValue == .inactive {
       ChildView()
     }
}

ChildView{
  Form{
    HStack{
        Button(action:{
           //do something...
        }){
          Text("Do it")
        }
    }
  }
}

2      

Hi,

I have faced such issue once and I solved it by adding frame to it.

You can try like this,

    Button(action:{
       //do something...
    }){
      Text("Do it")
      .frame(width: 200, height: 200)
    }

2      

@iRiziya thanks, i think what you're pointing out here is a lack of padding a the "touch" surface beeing too small to be detected.. but my problem doesn't seems to be here. I've solved it out by removing the Form

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.