Home:ALL Converter>BLKFlexibleHeightBar behavior definer does not conform to UITableViewDelegate

BLKFlexibleHeightBar behavior definer does not conform to UITableViewDelegate

Ask Time:2016-08-31T03:40:05         Author:JoeVictor

Json Formatter

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?!

Author:JoeVictor,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39235831/blkflexibleheightbar-behavior-definer-does-not-conform-to-uitableviewdelegate
Yves :

I was having this problem.\n\nYou´ll need to edit the BLKDelegateSplitter.h @interface declaration. Replace it with: \n\n@interface BLKDelegateSplitter : NSObject <NSObject, UITableViewDelegate>\n\n\nSource: https://github.com/bryankeller/BLKFlexibleHeightBar/issues/42",
2017-07-25T14:25:51
yy