我正在尝试创建一个填充为文本字段和标签的表格,但在填充它时遇到了棘手的问题。抛出错误,好像表格只接受字符串到其单元格中。
我的代码如下——我试图让它尽可能简短。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace Hello_Multiscreen
{
public class TableSource : UITableViewSource {
object[] tableItems;
string cellIdentifier = "TableCell";
public TableSource (object[] items)
{
tableItems = items;
}
public override int RowsInSection (UITableView tableview, int section)
{
return tableItems.Length;
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
// if there are no cells to reuse, create a new one
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
return cell;
}
}
}
在使用此表的屏幕类中,ViewDidLoad 方法具有
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// adds the table to the view
table = new UITableView(View.Bounds); // defaults to Plain style
// load in a string of the values from that database corresponds to all scope--allow user to click on them
UITextField txtFld = new UITextField();
object[] tableItems = new object[] {txtFld, txtFld, txtFld};
// select a table source--the table name is the same as the control id name that was dragged
table.Source = new TableSource(tableItems);
Add (table);
}