QuantumHoneybees QuantumHoneybees - 3 years ago 72
iOS Question

BLKFlexibleHeightBar behavior definer does not conform to UITableViewDelegate

So I'm using this library that allows me to make a bar on top of a tableview that compresses when I scroll down. Now I installed it in my Swift project using a bridging header. So I followed the implementation guide, converting all the code to Swift code. It all worked fine until I reached a problem in the "Configuring Bar Behavior" section.

Bar behavior definer is the part that knows when to scale up/down the bar depending on how far through you've scrolled in your table. So it uses the

UITableViewDelegate
(TVD) to do so. But looking at the source code for the BarBehaviorDefiner, you can see that it implements the
UIScrollViewDelegate
only.

This is the problem. I need to set the tableview's delegate to one of the objects of type BLKFlexibleHeightBarBehaviorDefiner, but they are not of type
UITableViewDelegate
.

self.tableView.delegate = (id<UITableViewDelegate>)myBar.behaviorDefiner;


Now I know that TVD implements SVD as part of it, but I can't set a SVD to something requiring a TVD.

Here's what I've tried:


  1. Linking my table as a UIScrollView instead of a UITableView. Code:

    @IBOutlet weak var table: UIScrollView!

    /*
    * irrelevant code *
    */

    headerBar.behaviorDefiner = SquareCashStyleBehaviorDefiner()
    table.delegate = headerBar.behaviorDefiner



This results in the bar actually compressing, but the table does not move with the bar. It just stays where it is, leaving a white space where the bar is compressed.


  1. Optionally casting like in the implementation guide. Code:

    @IBOutlet weak var table: UITableView!

    /*
    * irrelevant code *
    */

    headerBar.behaviorDefiner = SquareCashStyleBehaviorDefiner()
    table.delegate = headerBar.behaviorDefiner as? UITableViewDelegate



This doesn't cast it. The app does nothing when I scroll down the table.


  1. Forced casting to a
    UITableViewDelegate
    . Code:

    @IBOutlet weak var table: UITableView!

    /*
    * irrelevant code *
    */

    headerBar.behaviorDefiner = SquareCashStyleBehaviorDefiner()
    table.delegate = headerBar.behaviorDefiner as! UITableViewDelegate



This returns error
could not cast value of type 'UIScrollViewDelegate' to 'UITableViewDelegate'
.

I think it may be because I'm doing this in swift, but this error shouldn't be based on language?!

Answer Source

I was having this problem.

You´ll need to edit the BLKDelegateSplitter.h @interface declaration. Replace it with:

@interface BLKDelegateSplitter : NSObject <NSObject, UITableViewDelegate>

Source: https://github.com/bryankeller/BLKFlexibleHeightBar/issues/42

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download