0

I've a little problem with this:

gif animation

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:

  1. The main controller is FilterViewController inherit from UIViewController
  2. When the "Categories" row selected, an instantiation of CategoryFilterViewController created and the view added to the FilterViewController's view.
  3. 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()
    }
}
guiltance
  • 236
  • 1
  • 8

2 Answers2

0

This could help you to create expandable and collapsable tableview

http://www.appcoda.com/expandable-table-view/

On didSelectedRow at index change navigation bar title and scroll your table to particular index to bring it on top.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{

    self.title = // String from your array which is displayed on cellForRowAtIndex

    let no = indexPath.row + 4 // Particular no which scroll table view up side so your selected row comes on first

    let lastIndex = NSIndexPath(forRow: no, inSection: 0)

    tableView.scrollToRowAtIndexPath(lastIndex, atScrollPosition: .Bottom, animated: true)

}

Only 1 thing you have to compromise with backbutton and navigation bar tittle animation.

Backbutton, by using flag is_expandable or not you can pop view controller or collapse table.

Hope this will help you out to figure out your solution.

All the best.

Hasya
  • 9,792
  • 4
  • 31
  • 46
0

I finally found what's wrong

The second tableView top contraint on CategoryViewController was not at 0 value. I had set clipSubviews to false on the child tableView which mean top cell are still visible but cannot handle any interactions because it was out of frame.

Thank's to everyone answered, that helped me to find a solution

guiltance
  • 236
  • 1
  • 8