所以我开始学习 Swift,因为它看起来比 ObjC 好得多。但是我一定很累(现在是凌晨 2:37),因为我看不出为什么 Xcode 尖叫我试图调用未定义成员的问题。请看下面的代码:
PeopleStackViewDataSource.swift
import Foundation
import UIKit
protocol PeopleStackViewDataSource {
func stackViewNumberOfItems(stackView: PeopleStackView) -> Int
func stackViewGetView(indexPath: NSIndexPath) -> UIView
}
PeopleStackView.swift
import Foundation
import UIKit
class PeopleStackView: UIView {
var datasource: PeopleStackViewDataSource? {
didSet {
self.redraw()
}
}
var scaleDownBy: Double = 0.1
init(frame: CGRect) {
super.init(frame: frame)
}
init(frame: CGRect, datasource: PeopleStackViewDataSource) {
super.init(frame: frame);
self.datasource = datasource;
}
func numberOfItems() -> Int {
return self.datasource ? self.datasource.stackViewNumberOfItems(self) : 0
}
func redraw() {
}
}
问题是return self.datasource ? self.datasource.stackViewNumberOfItems(self) : 0
Xcode 说的这一行stackViewNumberOfItems(self)
PeopleStackViewDataSource?没有名为“stackViewNumberOfItems”的成员
那么,问题出在哪里?