Xcode问题类型“ XYZController”不符合协议

时间:2018-10-30 01:11:14

标签: ios swift

我有一个iOS项目,并通过Pods为我的项目实现了第3方库后,出现错误:

  

类型“ XYZController”不符合协议

当我单击错误并添加协议子时,Xcode将添加已实现的功能(cardForItemAt())。

但是,当我从头开始创建一个新项目并以相同的方式实现它时,我没有任何错误消息。

任何人都知道什么会导致此问题?在这种情况下我该怎么办? 我已经清理了构建,派生数据并重新启动了Xcode,但存在相同的错误。

这是我的ViewController失败:

import UIKIt
import VerticalCardSwiper

class MainViewController: UIViewController, VerticalCardSwiperDelegate, VerticalCardSwiperDatasource  {
    private var cardSwiper: VerticalCardSwiper!

    private var contactsDemoData: [Contact] = [
        Contact(name: "John Doe", age: 33),
        Contact(name: "Chuck Norris", age: 78),
        Contact(name: "Bill Gates", age: 62),
        Contact(name: "Steve Jobs", age: 56)
    ]

    override func viewDidLoad() {
        super.viewDidLoad()
        cardSwiper = VerticalCardSwiper(frame: self.view.bounds)
        cardSwiper.delegate = self
        cardSwiper.datasource = self
        cardSwiper.register(MainCard.self, forCellWithReuseIdentifier: "MainCard")
        view.addSubview(cardSwiper)
    }

    func cardForItemAt(verticalCardSwiperView: VerticalCardSwiperView, cardForItemAt index: Int) -> CardCell {
        let cardCell = verticalCardSwiperView.dequeueReusableCell(withReuseIdentifier: "MainCard", for: index) as! MainCard
        let _ = contactsDemoData[index]
        cardCell.setRandomBackgroundColor()
        return cardCell
    }

    func numberOfCards(verticalCardSwiperView: VerticalCardSwiperView) -> Int {
        return contactsDemoData.count
    }

    func willSwipeCardAway(card: CardCell, index: Int, swipeDirection: SwipeDirection) {
        // called right before the card animates off the screen.
    }

    func didSwipeCardAway(card: CardCell, index: Int, swipeDirection: SwipeDirection) {
        contactsDemoData.remove(at: index)
    }
}

class MainCard: CardCell {
    public func setRandomBackgroundColor(){
        let randomRed:CGFloat = CGFloat(arc4random()) / CGFloat(UInt32.max)
        let randomGreen:CGFloat = CGFloat(arc4random()) / CGFloat(UInt32.max)
        let randomBlue:CGFloat = CGFloat(arc4random()) / CGFloat(UInt32.max)
        self.backgroundColor = UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
    }

    override func layoutSubviews() {
        self.layer.cornerRadius = 12
        super.layoutSubviews()
    }
}

我在项目中根本不使用情节提要。

0 个答案:

没有答案