ios - 无法使用 BaseButtonBarPagerTabStripViewController 与自定义单元连接 XLPagertabStrip 导出

标签 ios objective-c iphone swift xlpagertabstrip

我想使用 XLPagerTabStrip 创建自定义选项卡,我正在使用 BaseButtonBarPagerTabStripViewController 和自定义 collectionview 单元格。但我遇到的问题是,我无法从我的类(class)连接 Buttonbarview 和 containerview,你能帮我解决一下吗?贝娄是我的类(class)

    import Foundation
import XLPagerTabStrip

class YoutubeExampleViewController: BaseButtonBarPagerTabStripViewController<YoutubeIconCell> {

    let redColor = UIColor(red: 221/255.0, green: 0/255.0, blue: 19/255.0, alpha: 1.0)
    let unselectedIconColor = UIColor(red: 73/255.0, green: 8/255.0, blue: 10/255.0, alpha: 1.0)

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "YoutubeIconCell", bundle: Bundle(for: YoutubeIconCell.self), width: { (cell: IndicatorInfo) -> CGFloat in
                return 55.0
        })
    }

    override func viewDidLoad() {
        // change selected bar color

        settings.style.buttonBarBackgroundColor = redColor
        settings.style.buttonBarItemBackgroundColor = .clear
        settings.style.selectedBarBackgroundColor = UIColor(red: 234/255.0, green: 234/255.0, blue: 234/255.0, alpha: 1.0)
        settings.style.selectedBarHeight = 4.0
        settings.style.buttonBarMinimumLineSpacing = 0
        settings.style.buttonBarItemTitleColor = .black
        settings.style.buttonBarItemsShouldFillAvailableWidth = true
        settings.style.buttonBarLeftContentInset = 0
        settings.style.buttonBarRightContentInset = 0



        changeCurrentIndexProgressive = { [weak self] (oldCell: YoutubeIconCell?, newCell: YoutubeIconCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
            guard changeCurrentIndex == true else { return }
            oldCell?.iconImage.tintColor = self?.unselectedIconColor
            newCell?.iconImage.tintColor = .white

        }
        super.viewDidLoad()
        navigationController?.navigationBar.shadowImage = UIImage()
        navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    }

    // MARK: - PagerTabStripDataSource

    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        let child_1 = FeedsTableViewController(style: .plain, itemInfo: IndicatorInfo(title: " HOME", image: UIImage(named: "c1")))
        let child_2 = FeedsTableViewController(style: .plain, itemInfo: IndicatorInfo(title: " TRENDING", image: UIImage(named: "d1")))
        return [child_1, child_2]
    }


    override func configure(cell: YoutubeIconCell, for indicatorInfo: IndicatorInfo) {
        cell.iconImage.image = indicatorInfo.image?.withRenderingMode(.alwaysTemplate)
    }

    override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
        super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
        if indexWasChanged && toIndex > -1 && toIndex < viewControllers.count {
            let child = viewControllers[toIndex] as! IndicatorInfoProvider
            UIView.performWithoutAnimation({ [weak self] () -> Void in
                guard let me = self else { return }
                me.navigationItem.leftBarButtonItem?.title =  child.indicatorInfo(for: me).title
            })
        }
    }

    // MARK: - Actions

    @IBAction func closeAction(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
}

最佳答案

我不知道作者的解决方案,因为我还没有尝试过,但我的解决方案(刚刚尝试并成功)是:

  • 注释掉继承自 BaseButtonBarPagerTabStripViewController 的类的所有代码

  • 编写具有相同名称的新类,继承自 ButtonBarPagerTabStripViewController(不是基础类,这就是神奇发生的地方)。

  • 返回到storyboard/xib 文件,现在您可以将outlet 与containerView 和buttonBarView 连接起来。

  • 之后,撤消您对类(class)所做的操作。

关于ios - 无法使用 BaseButtonBarPagerTabStripViewController 与自定义单元连接 XLPagertabStrip 导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43249919/

相关文章:

objective-c - 如何检查 Objective-C 中的字符是否为空?

objective-c - 对象-C : Convert an Array of objects into an NSDictionary for use with JSONRepresentation

iphone - UILabel setText 在 vi​​ewWillAppear 中不起作用

objective-c - 变量参数列表 - 内存管理错误

ios - 当应用程序进入后台/事件状态时安全地暂停/恢复远程 UIWebView WebSockets

javascript - phonegap android 控制台日志不工作

ios - 我如何订阅共享数据库的更改?

ios - 来自扩展的分段控制 subview

iphone - 在自定义 UITableViewCell 中访问 UITextField

iphone - 如何修改自定义GCD队列的优先级?