我有UITableViewSource我想从我添加到UITableViewSource的标签的Web服务中获取循环数据
Fisrt lable:Lblqut.text
第二个Lable:LblAnswer.text
我想在标签中显示UITableViewSource的数据。现在每个人都可以,但我在这行雇员中遇到问题。添加(item.Answ,item.AskID)
var employees = new List<Employee>
{
new Employee
{
Fullname="ahmed",
Department="Finance"
}
};
listVStud.Source = new EmployeesTVS(employees);
我的代码中出现问题
List<Employee> employees = new List<Employee>();
foreach (var item in e.Result)
{
employees.Add(item.Answ, item.AskID);
}
listVStud.Source = new EmployeesTVS(employees);
此课程雇员TVS
class EmployeesTVS : UITableViewSource
{
List<Employee> employees;
public EmployeesTVS(List<Employee> employees)
{
this.employees = employees;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = (EmployeeCell) tableView.DequeueReusableCell("Cell_id", indexPath);
var employee = employees[indexPath.Row];
cell.updatecell(employee);
return cell;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return employees.Count;
}
}
此班级员工
class Employee
{
public string Fullname
{
get;
set;
}
public string Department
{
get;
set;
}
此类EmployeeCell
public partial class EmployeeCell : UITableViewCell
{
public EmployeeCell (IntPtr handle) : base (handle)
{
}
internal void updatecell(Employee employee)
{
Lblqut.Text = employee.Fullname;
LblAnswer.Text = employee.Department;
}
}
答案 0 :(得分:1)
改为使用:
employees.Add(new Employee { Fullname = item.Answ, Department = item.AskID });