【发布时间】:2016-06-10 13:39:26
【问题描述】:
我有 UITableViewController。当用户单击单元格时,我需要打开另一个 ViewController。这是我的代码:
公共部分类 CCreateOrderOrderType : UITableViewController { 私有列表 orderTypes; 私有LoadingOverlay loadingOverlay; 公共 CCreateOrderOrderType(IntPtr 句柄):基(句柄) { }
public CCreateOrderOrderType (List<OrderType> orderTypes){
this.orderTypes = orderTypes;
}
public override void ViewDidLoad(){
TableView.Source = new OrderTypeTableSource (this, orderTypes);
}
}
public class OrderTypeTableSource : UITableViewSource {
private CCreateOrderOrderType owner;
private List<OrderType> orderTypes;
private string cellIdentifier = "orderGroupCI";
public OrderTypeTableSource(CCreateOrderOrderType owner, List<OrderType> orderTypes){
this.owner = owner;
this.orderTypes = orderTypes;
}
public override nint RowsInSection (UITableView tableview, nint section){
return orderTypes.Count;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
OrderType item = orderTypes[indexPath.Row];
if (cell == null)
{
cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier);
cell.DetailTextLabel.Text = item.orderTypeName;
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
}
return cell;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
CCreateOrderC clientOrderCreate = owner.Storyboard.InstantiateViewController ("CCreateOrderC") as CCreateOrderC;
clientOrderCreate.selectedOrderType = orderTypes [indexPath.Row];
if (clientOrderCreate != null) {
owner.NavigationController.PushViewController (clientOrderCreate, true);
}
tableView.DeselectRow (indexPath, true);
}
}
但我在第一行有空指针异常。怎么了?
【问题讨论】:
-
您的问题中有一些西里尔文字,您可以编辑它以使其更清晰吗? :D
-
@Zil,对不起,我删除了这些符号
标签: c# ios xamarin xamarin.ios