【发布时间】:2020-10-12 09:20:08
【问题描述】:
我正在尝试将一段 Swift 代码转换为 c#。
我知道 c# 方法扩展,但在这种情况下,swift 代码继承了一个类:
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return characters.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = characters[indexPath.row]
return cell
}
}
在 c# 中可以做到这一点吗?
编辑:代码来自here。
编辑 2:在 Xamarin docs 中找到 solution。
【问题讨论】:
-
不,Swift 扩展更强大。但这听起来像是一个 XY 问题。为什么要尝试将表格视图代码转换为 C#?您是否可能使用 Xamarin.iOS 或其他东西?
-
UITableViewDataSource不是一个类,而是一个协议,所以这个扩展声明了协议的一致性,而不是继承。 -
确实我正在使用 Xamarin.iOS 并尝试转换 this sample。
-
@DávidPásztor 那将是 c# 中的一个接口
标签: c# xamarin.ios uikit