C# 未调用选定的iOS行
我在我选择的行方法中添加了一条打印语句,但从未调用该语句:C# 未调用选定的iOS行,c#,ios,xamarin.ios,xamarin,C#,Ios,Xamarin.ios,Xamarin,我在我选择的行方法中添加了一条打印语句,但从未调用该语句: public override void RowSelected (UITableView tableView, NSIndexPath indexPath) { Console.WriteLine ("Row selected"); } 我的单元格有一个UIImageView,它覆盖整个单元格,作为背景图像。这是否会导致行无法识别触摸?必须调用: MyTableView.AllowsSelec
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine ("Row selected");
}
我的单元格有一个UIImageView
,它覆盖整个单元格,作为背景图像。这是否会导致行无法识别触摸?必须调用:
MyTableView.AllowsSelection = true;
默认情况下,它必须设置为false
。必须调用:
MyTableView.AllowsSelection = true;
默认情况下,它必须设置为
false
。添加最新版本:Visual Studio/Xamarin iOS/C#
1) 将IUITableViewDelegate添加到ViewController.cs
2) 在ViewDidLoad上:
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.yourTableview.Delegate = this;
this.yourTableview.AllowsSelection = true;
}
3) 实现IUITableViewDelegate方法
[Export("tableView:didSelectRowAtIndexPath:")]
public virtual void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine("Row Selected");
}
请注意,如果未添加[Export(“tableView:DidSelectRowatineXpath:”)],则不会调用RowSelected。添加最新版本:Visual Studio/Xamarin iOS/C# 1) 将IUITableViewDelegate添加到ViewController.cs 2) 在ViewDidLoad上:
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.yourTableview.Delegate = this;
this.yourTableview.AllowsSelection = true;
}
3) 实现IUITableViewDelegate方法
[Export("tableView:didSelectRowAtIndexPath:")]
public virtual void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine("Row Selected");
}
请注意,如果未添加[Export(“tableView:didSelectRowAtIndexPath:”)],则不会调用RowSelected。您应该将图像设置为背景视图。否则它将覆盖单元格。@CrimsonChris背景视图不能是uiimage吗?或者我需要强制转换它吗?图像视图是视图的一个子类。您不需要强制转换它。@CrimsonChris我已将其更改为背景视图,但仍无法调用选定的行。在没有图像视图的情况下,它可以工作吗?您应该将图像设置为背景视图。否则它将覆盖单元格。@CrimsonChris背景视图不能是uiimage吗?或者我需要强制转换它吗?图像视图是视图的一个子类。您不需要强制转换它。@CrimsonChris我已将其更改为背景视图,但仍无法调用选定的行。在没有图像视图的情况下,它可以工作吗?