子类SlackTextViewController collectionview

时间:2018-08-03 19:21:53

标签: ios swift

我正在使用SlackTextViewController创建聊天应用。我还使用IGListKit来显示数据。

    class ChatTest: SLKTextViewController, ListAdapterDataSource {

    var room: Room!
    var messages = [Message]()

    lazy var adapter: ListAdapter = {
        return ListAdapter(updater: ListAdapterUpdater(), viewController: self, workingRangeSize: 2)
    }()


    override var collectionView: UICollectionView {
        get {
            return super.collectionView!
        }
    }


    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = .white
        collectionView.backgroundColor = .black
        view.addSubview(collectionView)
        adapter.collectionView = collectionView
        adapter.dataSource = self
        initMessages()
        setNavigationItemTitle()
        configureSlackCollectionViewController()

    }
}

但是在覆盖collectionview时出现此错误:

  

线程1:致命错误:展开包装时意外发现nil   可选值

我可以使用其他collectionView代替SLKTextViewController collectionview吗?

新尝试:

class ChatTest: SLKTextViewController, ListAdapterDataSource {

var room: Room!
var messages = [Message]()

lazy var adapter: ListAdapter = {
    return ListAdapter(updater: ListAdapterUpdater(), viewController: self, workingRangeSize: 2)
}()


override init?(collectionViewLayout layout: UICollectionViewLayout) {
    super.init(collectionViewLayout: layout)
}

required init?(coder decoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}


let collect = UICollectionView (
    frame: .zero, collectionViewLayout: ListCollectionViewLayout(stickyHeaders: false, topContentInset: 0, stretchToEdge: false)
)

override var collectionView: UICollectionView {
    get {
        return collect 
    }
}

enter image description here

  

不能为没有参数的'ChatTest'类型调用初始化器

0 个答案:

没有答案