I've a little problem with this:
A tableview is added on my view to show categories and another tableview added when category selected for display subcategories. But interaction with the top cell is not recognized and I don't understand why ! If anyone as an idea to fix this problem, or another way to make those animations possible ..
Code is complicated to show but I'll try to explain clearly:
- The main controller is
FilterViewController
inherit fromUIViewController
- When the "Categories" row selected, an instantiation of
CategoryFilterViewController
created and the view added to theFilterViewController's
view. - On the
CategoryFilterViewController
, when a row selected, I instantiate new tableView and add it to the view.
CategoryViewController storyboard view
A part of FilterViewController
, variables and outlets
You can see I used SnapKit to make some constraints programmatically
var contentViewCatHeightContrain: Constraint? = nil
var contentViewCatBottomContrain: Constraint? = nil
@IBOutlet weak var filterTableView: UITableView!
@IBOutlet weak var submitFilterButton: UIButton!
You see here, when "Categories" row selected, I run this code.
func displayCat(show: Bool, cell: FilterCell) {
let cellRow = self.filterTableView.indexPathForCell(cell)!
if(cellRow.row == 0) {
if(self.viewModel.categoryContentsView == nil) {
if let vc = self.storyboard?.instantiateViewControllerWithIdentifier("CategoryFilterView") as? CategoryFilterView {
self.viewModel.categoryContentsView = vc
self.viewModel.categoryContentsView.view.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 0)
self.view.addSubview(self.viewModel.categoryContentsView.view)
self.addChildViewController(vc)
self.viewModel.categoryContentsView.view.snp_makeConstraints(closure: { (make) -> Void in
self.contentViewCatHeightContrain = make.height.equalTo(0).constraint
make.left.equalTo(0)
make.right.equalTo(0)
self.contentViewCatBottomContrain = make.bottom.equalTo(0).constraint
})
}
}
self.viewModel.categoryContentsView.view.didMoveToSuperview()
self.view.bringSubviewToFront(self.viewModel.categoryContentsView.view)
}
}
And on the CategoryViewController
, outlets:
@IBOutlet weak var catTableView: UITableView!
@IBOutlet weak var topCatTableView: NSLayoutConstraint!
@IBOutlet weak var subCatHeightContrain: NSLayoutConstraint!
@IBOutlet weak var subCatTableView: UITableView!
and when row selected:
func showHideTableView(show: Bool) {
if(show) {
self.topCatTableView.constant = -75
self.subCatHeightContrain.constant = UIScreen.mainScreen().bounds.size.height - 95
}
else {
self.topCatTableView.constant = 0
self.subCatHeightContrain.constant = 0
self.catTableView.reloadData()
}
}