我想在 tvos 中使用 uitableview 来显示字符串数据列表,但编译器在生成的标头中遇到以下错误:
"No type or protocol named 'UITableViewDataSource'"
And "Attempting to use the forward class 'UITableView' as superclass of 'TWOSSelectionTableTVOS'"
Run Code Online (Sandbox Code Playgroud)
即使这段代码正在工作ios。
我的代码结构如下:
选择表.swift:
import UIKit
class TWOSSelectionTableTVOS : UITableView
{
private var vDataSrc:[String]!
func SetDataSrc (_ pDataSrc:[String])
{
self.vDataSrc = pDataSrc
}
func UpdateDataSrc (_ pStringList:[String])
{
self.vDataSrc += pStringList
}
func GetDataSrc () -> [String]
{
return self.vDataSrc
}
}
Run Code Online (Sandbox Code Playgroud)
PaintUI.swift:
import UIKit
@objc
class PaintUI: NSObject,UITableViewDelegate, UITableViewDataSource {
static let uShared = PaintUI ()
@objc
static func updateUIMessage() {
DispatchQueue.main.async {
ExecuteInlineSelectionTable ()
}
}
func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell (withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "hello"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let viewcontroller: TWIOSViewController!
viewcontroller = StaticContext.sViewController
}
public static func ExecuteInlineSelectionTable ()
{
let selectiontable:TWOSSelectionTableTVOS!
selectiontable = TWOSSelectionTableTVOS ()
selectiontable.register (UITableViewCell.self, forCellReuseIdentifier: "cell")
selectiontable.dataSource = uShared
selectiontable.delegate = uShared
selectiontable.isScrollEnabled = true
// TODO : will add selection table in view heriearchy but currently getting compilation error
}
}
Run Code Online (Sandbox Code Playgroud)
最后调用 PaintUI.updateUIMessage () ,它仅针对 tvOS 出现上述错误,但在 ios 代码中工作正常。
| 归档时间: |
|
| 查看次数: |
34 次 |
| 最近记录: |