Compiler not liking UIScrollViewDelegate with Swift

I am getting an error, when implementing a UIScrollView into a UITableViewCell.

class MyItemTableViewCell: UITableViewCell, UIScrollViewDelegate {

...  

var scrollView: UIScrollView = {
        let scroll = UIScrollView()
        scroll.showsHorizontalScrollIndicator = false
        scroll.delegate = self
        return scroll;
        }()

...

func scrollViewDidScroll(scrollView: UIScrollView!) {
     ...   
    }

func scrollViewWillEndDragging(scrollView: UIScrollView!, velocity: CGPoint, targetContentOffset: CMutablePointer<CGPoint>) {
     ...   
    }
...
}

The compiler gives me an error on the line scroll.delegate = self saying that the Type MyItemTableViewCell does not conform to protocol ‘UIScrollViewDelegate’

  • Xamarin iOS localization using .NET
  • Geofencing iOS 6
  • Looping Through NSAttributedString Attributes to Increase Font SIze
  • UI test fails when it types text into a text view when run by an Xcode bot
  • How do you access command line arguments in Swift?
  • XMLRPC-iOS for iOS project
  • Never mind the fact, that the methods in the protocol are all documented as optional (https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/index.html), but I have two implemented.

    What does the compiler want from me?

    Thanks

    Solutions Collect From Internet About “Compiler not liking UIScrollViewDelegate with Swift”

    During the init cycle, self isn’t usable until all properties have been initialized. Change it to:

    class MyItemTableViewCell: UITableViewCell, UIScrollViewDelegate {
    
        var scrollView: UIScrollView
    
        func scrollViewDidScroll(scrollView: UIScrollView!) {
        }
    
        func scrollViewWillEndDragging(scrollView: UIScrollView!, velocity: CGPoint, inout targetContentOffset: CGPoint) {
        }
    
        init() {
            scrollView = UIScrollView()
            scrollView.showsHorizontalScrollIndicator = false
            super.init(style:UITableViewCellStyle.Default, reuseIdentifier:"cell")
            scrollView.delegate = self
        }
    }