簡體   English   中英

Swift 3轉換“沒有成員”錯誤

[英]Swift 3 conversion “has no member” error

我正在嘗試將項目轉換為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,在節:)'與任何可用的重載都不匹配”

有人可以協助解決Swift 3的轉換問題嗎? 當我評論這些內容時,一切都正常,所以這是最后一步。 提前致謝。

在選擇器中替換標簽sender的下划線。

#selector(DemoViewController.swipeHandler(sender:))

關於索引路徑,swift3中的新方法是:

NSIndexPath(row: currentIndex, section: 0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM