在 Objective-C 中:
@interface CustomDataSource : NSObject <UITableViewDataSource>
@end
在 swift 中:
class CustomDataSource : UITableViewDataSource {
}
但是会出现错误信息:
正确的方法应该是什么?
最佳答案
Type 'CellDatasDataSource' does not conform to protocol 'NSObjectProtocol'
你必须让你的类继承自 NSObject
以符合 NSObjectProtocol
。 Vanilla Swift 类没有。但是 UIKit
的许多部分都需要 NSObject
s。
class CustomDataSource : NSObject, UITableViewDataSource {
}
但是这个:
Type 'CellDatasDataSource' does not conform to protocol 'UITableViewDataSource'
预计。在您的类实现协议(protocol)的所有必需方法之前,您将收到错误消息。
所以开始编码:)
https://stackoverflow.com/questions/24991018/