ios - Swift 3 转换 "has no member"错误

标签 ios xcode error-handling swift3

我正在尝试将我的项目转换为 Swift 3,并且已经解决了大部分错误,但我在调用我的手势识别器时遇到问题。这是我的代码:

func addGestureToView(toView: UIView) {
    let gesutereUp = Init(UISwipeGestureRecognizer(target: self, action: #selector(DemoViewController.swipeHandler(_:)))) {
      $0.direction = .Up
    }

    let gesutereDown = Init(UISwipeGestureRecognizer(target: self, action: #selector(DemoViewController.swipeHandler(_:)))) {
      $0.direction = .Down
    }
    toView.addGestureRecognizer(gesutereUp)
    toView.addGestureRecognizer(gesutereDown)
  }

  func swipeHandler(sender: UISwipeGestureRecognizer) {
    let indexPath = NSIndexPath(forRow: currentIndex, inSection: 0)
    guard let cell  = collectionView?.cellForItemAtIndexPath(indexPath) as? DemoCollectionViewCell else { return }

它给我错误提示 gestureUp 和 gestureDown 都“没有成员‘swipeHandler’”

同样在“let indexPath...”这一行,我收到一条错误消息“参数标签‘(forRow, in section:)’不匹配任何可用的重载”

有人可以帮忙解决 Swift 3 的转换问题吗?当我评论这些行时,一切正常,所以这是最后一篇。提前致谢。

最佳答案

替换选择器中标签sender的下划线。

#selector(DemoViewController.swipeHandler(sender:))

关于索引路径,swift3中新的方法是:

NSIndexPath(row: currentIndex, section: 0)

关于ios - Swift 3 转换 "has no member"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39627149/

相关文章:

ios - 我应该用计时器删除缓存还是?

.htaccess - 使用两个404页面未找到的页面来表示网站的不同语言版本

ios 9 应用程序不在后台报告位置

ios - ios APP中的侧边栏或抽屉导航?

Xcode 遇到意外错误 (0x01c)

MVC 架构中的 iOS Singleton 类

ios - 尝试通过应用程序图标上的 3d 触摸将 VC 从 performActionFor shortcutItem 嵌入到 NavigationVC

api - 如何向 Amadeus API 发出请求?遇到网络错误

forms - laravel4表单验证错误

ios - AMSlideMenu 菜单的深度效果