当我从UITableViewSource
中单击RowSelected时,我想要打开viewcontroller我在打开UIViewController时使用此代码
非常感谢任何帮助。
感谢
MainStudUn controller =this.Storyboard.InstantiateViewController("MainStudUn") as MainStudUn;
this.NavigationController.PushViewController(controller, true);
但是在使用UITableViewSource
的代码时遇到了问题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;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
var SelectName = employees[indexPath.Row];
Globals.AskX = SelectName.Fullname;
Globals.AnswerX = SelectName.Department;
//OpnWerd();
//MainStudUn controller = this.Storyboard.InstantiateViewController("MainStudUn") as MainStudUn;
//this.NavigationController.PushViewController(controller, true);
}
}
答案 0 :(得分:1)
将ViewController本身设置为dataSource的初始化构造函数中的参数。
ViewController中的
this.TableView.Source = new EmployeesTVS(tableItems, this);
在dataSource
中AskStud owner; //this is your VC class not ViewController,it's just a sample.
public EmployeesTVS(List<Employee> employees, AskStud owner)
{
this.employees = employees;
this.owner = owner;
}
用法:
MainStudUn controller =this.owner.Storyboard.InstantiateViewController("MainStudUn") as MainStudUn;
//OR
//UIStoryboard Storyboard = UIStoryboard.FromName("StoryBoardName", null);
//MainStudUn controller = Storyboard.InstantiateViewController("MainStudUn") as MainStudUn;
this.owner.NavigationController.PushViewController(controller, true);