Flow:
- AViewController(modal on
MainViewController)- FooView(Cell click) -> This view is like
cell- BViewController -> modal on
AViewController
- BViewController -> modal on
- FooView(Cell click) -> This view is like
I want BViewController to be present when I click on FooView in AViewController.
AViewController is presenting with modal.
BViewController is presenting with modal.
I want to present a nested modal.
Since FooView is a UIView, I created a protocol inside FooView. I trigger the function in the protocol with the button in the FooView and call this function in the AViewController. I want the function running in AViewController to present BViewController in AViewController, but I am facing this error.
Error:
Thread 1: "-[ProjectName.BViewController _mutableLayoutGuides]: unrecognized selector sent to instance 0x7f8d97b892e0"
AViewController:
class AViewController: PresentableFilterPageForItemPage {
...
override func viewDidLoad() {
super.viewDidLoad()
...
}
func presentFilterPageForItemPage() {
let vc = FilterItemsVC()
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: false, completion: nil)
}
func updateFilterItems(facets: [Facet]) {
for item in facets {
let filterItem = FooView() // <--- FooView here
filterItem.titleLabel.text = item.definition
filterItem.subTitleLabel.text = "Tümü"
filterItem.delegate = self
filterItemStackView.addArrangedSubview(filterItem)
}
}
}
FooView:
protocol PresentableFilterPageForItemPage: AnyObject {
func presentFilterPageForItemPage()
}
class FooView: UIView {
var buttonView: UIButton = {
let button = UIButton(type: .custom)
button.addTarget(self, action: #selector(didTappedButton), for: .touchUpInside)
return button
}()
var delegate: PresentableFilterPageForItemPage?
override func setupAfterInit() {
}
@objc func didTappedButton() {
delegate?.presentFilterPageForItemPage()
}
}
BViewController
class BViewController: UIViewController {
...
override func viewDidLoad() {
super.viewDidLoad()
...
}
func updateFilterItems(facets: [Facet]) {
for item in facets {
let filterItem = FooView()
filterItem.titleLabel.text = item.definition
filterItem.subTitleLabel.text = "Tümü"
filterItemStackView.addArrangedSubview(filterItem)
}
}
}