데이터의 각 행에 대해 완전히 새로운 TableView를 만듭니다. 대신 데이터를 반복하여 표시하려는 모든 데이터가 포함 된 데이터 구조 (목록, 배열 등)를 만든 다음 해당 데이터를 TableView/Source에 전달해야합니다.
public List<DemoClass> getDemoClassList()
{
List<DemoClass> lstDemoClass;
DemoClass objDemoClass;
try
{
String strCommandText;
strCommandText = "SELECT * FROM DemoClass ";
command = new SqliteCommand(strCommandText, connection);
lstDemoClass = new List<DemoClass>();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
objDemoClass = new Homes(false);
objDemoClass.ID = Convert.ToInt32(reader[0]);
objDemoClass.Name = Convert.ToString(reader[1]);
lstDemoClass.Add(objDemoClass);
}
}
return lstDemoClass;
}
catch (Exception ex)
{
throw ex;
}
finally
{
command.Dispose();
command = null;
lstDemoClass = null;
objDemoClass = null;
}
}
public void BindList()
{
List<DemoClass> lstDemoClass = new List<DemoClass>();
DemoClass hm = new DemoClass();
lstDemoClass = (List<DemoClass>)hm.getDemoClassList();
TableViewDataSource tdatasource = new TableViewDataSource(this, lstDemoClass);
table.Hidden = false;
table.DataSource = tdatasource;
table.Delegate = new TableViewDelegate(this, table, lstDemoClass);
table.ReloadData();
}
getDemoClassList은() SQLite는 테이블에서 검색된 목록을 제공하며, 나중에 테이블 데이터 소스에 대한 목록을 바인딩 할 수 있습니다 :
cmd.CommandType = CommandType.Text;
dr = cmd.ExecuteReader();
// you will need a class mydata with Num and Name properties
List<mydata> data = new List<mydata>();
while (dr.Read())
{
data.Add(new mydata { Num = dr["admin_num"], Name = dr["name"] });
}
dr.Close();
var table = new UITableView(this.retrieveData.Frame);
table.Source = new TableSource(data);
Add (table);
조언을 주셔서 감사합니다. num과 name 속성이 무엇인지 알 수 있습니까? – zhihao
코드에 따라 테이블에 표시하려는 데이터 요소가 있다고 가정합니다. 이 클래스는 데이터 모델이 무엇이든 반영해야합니다. – Jason
내가 참조 할 수있는 예제가 있습니까? – zhihao