EvOlaNdLuPiZ
EvOlaNdLuPiZ

Reputation: 600

UiTextField inside UiStackView is not responding

Goal: I'm building a time sheet using swift ui.

Question: At the top I have class A that inherits from UiViewController. It lays out a UiStackView in a vertical stack to divide the screen into three: top,center,bottom. I'm having issues inside the center view. I can only get interaction with the UiTextField inside the center if I add it directly.

Inside the center view, I have a class B that inherits from UiView. Within the class I have another UiStackView that will add a horizontal stack to layout some items nicely.

I've made a class C in the same file outside of the center view class, and it inherits from UiView. It contains a UiTextField that I setup and add.

Here's where things get weird, I can do inside class B, and I will be able to work with the UiTextField just fine:

`let temp = ClassC (inherits UiView)
self.addSubView(temp)` <- works

`ClassBUiStackView.addSubView(ClassC)
UiView temp = UiView(...)
temp.addSubView(ClassBUiStackView)
self.addSubView(temp)` <- fails

Let me provide some actual code:

`class A: UiViewController{
 override func viewDidLoad(){
  super.viewDidLoad()
  self.top = ...
  self.cnr = Class B
  self.btm = ...
  self.ClassAUiStackView(arrangedSubviews: [top,cnr,btm])
  ...constraints...
  self.view.addSubview(ClassAUiStackView)
 }
}
class B: UiView{
 override init(...){
  super.init(...)
  self.ClassBUiStackView(...x,y,width,heigh...)
  ...constraints...
  let temp = UiView(...)
  self.ClassBUiStackView.addSubView(ClassC)
  temp.addSubView(ClassBUiStackView)
 }
}
class C: UiView{
 var UiTF: UiTextField!
 required init(..., classB, ...){
  ...setup UiTf...
  self.UiTF.addTarget(self, action: #selector(uitfAction), for: .allEvents)
 self.addSubView(UiTf)
 }
 @objc func uitfAction(senderL UITextField!){
  ...some action...
 }
}
`

Deep Nesting UiView

UiView example #01

UiView example #02

UiView example #03

Any help on this would be much appreciated. This is my first Swift app so I'm still a newbie. Please elaborate as much, I will read it all (multiple-times). Thank you !

Upvotes: 2

Views: 1134

Answers (1)

EvOlaNdLuPiZ
EvOlaNdLuPiZ

Reputation: 600

i found the answer that will make all my ui components responsive again, i had to add uiStackView.translatesAutoresizingMaskIntoConstraints = true, if this is taken away or set to false, the ui components do not respond.

Upvotes: 1

Related Questions