0

I have a tableView where when I call viewForHeaderInSection before I return the cell. I have this code:

headerCell.layer.zPosition = headerCell.layer.zPosition-1 

Now this works in the sense that the cells scroll over the section header which is was I want. But the cell has 3 buttons at the bottom of the frame, when the those buttons scroll over (or should i say under) the sections header content view, the view blocks the buttons and I can no longer tap the buttons even though I can still see them, this is because the cells content view is rendered over the headers view.

If I go in view hierarchy, the header content view is above the cell view which is to blame for blocking the buttons actions.

Does anyone have a work around? or know how to change the headerCell's Zposition to be behind the button? I've tried so many things but I need help.

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    if (cellIdentifier == "vivrCell") {
        println(screenSize.width)
        if (screenSize.width < 370) {
            return 180
        }else{
            return 220
        }
    }else {
        return 0.0
    }
}

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if (cellIdentifier == "vivrCell") {
        let headerCell = mainTable.dequeueReusableCellWithIdentifier("vivrHeaderCell") as vivrHeaderCell
        headerCell.productID = self.feedReviewResults![section]["product"]["id"].stringValue
        headerCell.cellDelegate = self
        headerCell.clipsToBounds = false
        headerCell.layer.zPosition = headerCell.layer.zPosition-1
        return headerCell
    }
    return nil
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    switch cellIdentifier {
        case "vivrCell":
            return self.feedReviewResults?.count ?? 0
        case "newCell":
            return 1
    default:
        return 1

    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 1
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    switch cellIdentifier{
        case "buzzCell":
            var buzzcell = mainTable.dequeueReusableCellWithIdentifier(cellIdentifier) as buzzCell
            return buzzcell
        case "vivrCell":
            var vivrcell = mainTable.dequeueReusableCellWithIdentifier(cellIdentifier) as vivrCell
            vivrcell.review = self.feedReviewResults![indexPath.section]
            vivrcell.reviewID = self.feedReviewResults![indexPath.section]["id"].stringValue
            if let state = self.feedReviewResults![indexPath.section]["current_helpful"].boolValue as Bool?{
                vivrcell.helpfullState = state
            }
            vivrcell.wishlistState = true 
            vivrcell.cellDelegate = self
            vivrcell.layer.zPosition = vivrcell.layer.zPosition
            vivrcell.backgroundView = nil
            vivrcell.contentView.backgroundColor = UIColor.clearColor()
            return vivrcell
        default:
            let noNewProductsView = UIView(frame: CGRectMake(0, 0, self.view.frame.width, self.view.frame.height))
            noNewProductsView.backgroundColor = UIColor.whiteColor()
            let checkBackLabel = UILabel(frame: CGRectMake(0, 0, 200, 60.0))
            checkBackLabel.numberOfLines = 3
            checkBackLabel.textAlignment = NSTextAlignment.Center
            checkBackLabel.center = CGPointMake(self.view.center.x, self.view.center.y-100)
            checkBackLabel.text = "Check back for new products!"
            noNewProductsView.addSubview(checkBackLabel)
            var newcell = mainTable.dequeueReusableCellWithIdentifier(cellIdentifier) as newCell
            newcell.contentView.addSubview(noNewProductsView)
            return newcell

    }
}
AJF
  • 11,767
  • 2
  • 37
  • 64
  • I asked a similar question yesterday, I've linked to a post with quite a few answers. Maybe it'll be useful to you: http://stackoverflow.com/questions/30203010/how-do-i-change-the-z-index-or-stack-order-of-uiview – Dan Beaulieu May 13 '15 at 16:21

3 Answers3

0

Perhaps all you need is for taps on the header to be ignored. Set userInteractionEnabled = NO on the header.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
  • That works but Now i Have another problem. The header Cell has a button with a function and segue attatched to it... How do i enable that button only? – Maxwell Bo Blessen May 14 '15 at 00:57
0

If userInteractionEnabled to NO isn't working as you also have buttons on the section header, add this to your header's subclass:

// We don't want touches, but we do want our subviews to get them.
// (So userInteractionEnabled = NO won't work, that'll stop subviews getting touches)
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    id hitView = [super hitTest:point withEvent:event];
    return (hitView == self) ? nil : hitView;
}
Graham Perks
  • 23,007
  • 8
  • 61
  • 83
0
sectionView.userInteractionEnabled = false
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Adam Smaka
  • 5,977
  • 3
  • 50
  • 55