將UIScrollView
編譯爲UITableViewCell
時出現錯誤。編譯器不喜歡用Swift編寫的UIScrollViewDelegate
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>) {
...
}
...
}
編譯器給我一個錯誤上說,Type MyItemTableViewCell does not conform to protocol ‘UIScrollViewDelegate’
沒關係的事實,即在協議的方法都記錄爲可選(https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/index.html)行scroll.delegate = self
,但我有兩個實現。
編譯器對我有什麼要求?
感謝
更改'targetContentOffset'鍵入inout CGPoint? –
@JackWu:試過了 - 沒有運氣。 :-( – Joseph
@David:我根據文檔對其進行了建模:https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIScrollViewDelegate/scrollViewWillEndDragging:withVelocity:targetContentOffset: – Joseph