csharp 所有样板代码都需要在C#中启动并运行自定义iOS UITableViewController
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 所有样板代码都需要在C#中启动并运行自定义iOS UITableViewController相关的知识,希望对你有一定的参考价值。
public class TableViewController : UITableViewController
{
static readonly NSString CellId = new NSString ("C");
readonly TableViewSource source = new TableViewSource ();
readonly List<string> rows = new List<string> ();
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
try {
TableView.RegisterClassForCellReuse (typeof(TableViewCell), CellId);
source.Controller = this;
TableView.Source = source;
} catch (Exception ex) {
Console.WriteLine (ex);
}
}
async Task OnRowSelectedAsync (int index)
{
var r = rows [index];
// Do something awesome with r
}
class TableViewCell : UITableViewCell
{
public TableViewCell ()
{
}
public TableViewCell (IntPtr handle) : base (handle)
{
}
public void Bind (string value)
{
DetailTextLabel.Text = value ?? "";
}
}
class TableViewSource : UITableViewSource
{
public TableViewController Controller;
public override nint RowsInSection (UITableView tableview, nint section)
{
try {
return Controller.rows.Count;
} catch (Exception ex) {
Console.WriteLine (ex);
return 0;
}
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
try {
var c = (TableViewCell)tableView.DequeueReusableCell (CellId);
c.Bind (Controller.rows [indexPath.Row]);
return c;
} catch (Exception ex) {
Console.WriteLine (ex);
return new TableViewCell ();
}
}
public override async void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
try {
await Controller.OnRowSelectedAsync (indexPath.Row);
} catch (Exception ex) {
Console.WriteLine (ex);
}
}
}
}
以上是关于csharp 所有样板代码都需要在C#中启动并运行自定义iOS UITableViewController的主要内容,如果未能解决你的问题,请参考以下文章
csharp 可绑定类减少mvvm中的样板代码(实现INotifyPropertyChanged)
ABP项目启动及源代码结构
无法解决对样板项目的依赖
在没有样板的协议中需要一个 SwitftUI 视图
C++ 错误代码样板的模板与宏
收集启动函数