[ad_1]
The behavior of my app involves adding views (built programmatically inside a struct) from another controller to the main controller. The desired behavior is that once these views are added to the main controller, I can tap on a view and it will segue into another view controller displaying the object’s respective attributes.
I’ve been tirelessly trying to figure this out, but I have no idea how I could lay it out. This is what I have now and roughly how I’m imagining it:
struct View {
var newView = UIView()
var newLabel = UILabel()
init(viewName: String) {
newLabel.text = viewName
newView.addSubview(newLabel)
}
}
view = View(viewName: "view1")
view1 = View(viewName: "view2")
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationVC = segue.destination as! MainViewController
destinationVC.mainStack.addArrangedSubview(view.newView)
destinationVC.mainStack.addArrangedSubview(view1.newView)
}
- View 1 and View 2 are stacked on the main controller
- View 1 contains labels reflecting its object’s attributes
- Tap on View 1
- Segue to Info controller showing View 1’s attributes
- View 2 contains labels reflecting its object’s attributes
- Tap on View 2
- Segue to Info controller showing View 2’s attributes
[ad_2]