【问题标题】:iCarousel error in xcode 9xcode 9中的iCarousel错误
【发布时间】:2018-12-13 15:12:26
【问题描述】:

我尝试按照本教程实现 iCarousel:https://medium.com/@arb1nsnmgl/icarousel-walkthrough-swift-3-0-887554155242 但是在尝试实现 @protocol 时,它给了我 4 条错误消息:

  1. 协议类型中应为“{”
  2. 需要一个属性名称
  3. 协议“iCarouselDataSource”不能嵌套在另一个声明中
  4. 协议不允许泛型参数;改用关联类型

目前代码如下:

import UIKit
class ViewController: UIViewController {

@IBOutlet var carouselView: iCarousel!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    //Testing
    @protocol iCarouselDataSource <NSObject>
    -(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel;
    -(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(nullable UIView *)view;

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

【问题讨论】:

    标签: swift xcode icarousel


    【解决方案1】:

    你在错误的地方添加它所以删除

    @protocol iCarouselDataSource <NSObject>
    -(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel;
    -(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(nullable UIView *)view;
    

    来自viewDidLoad 方法。

    以上方法是委托方法。您需要按照教程中的说明添加它。

    检查点 11。

    同时确认第 8 点所示的代表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      • 2018-06-30
      相关资源
      最近更新 更多