如何在xamarin.ios

时间:2017-01-17 05:31:31

标签: ios xamarin xamarin.ios

我正在研究xamarin.ios。我创建了一个UITableView并绑定了一些数据。现在我想在表的UITableViewCell上使用LongPressGesture。我在LongPressGesture上打开一个弹出窗口,想要显示与所选行相关的数据。但我没有得到如何在LongPress上获取所选行的索引路径。 请更新我如何在longpress手势上获取indexpath值?

2 个答案:

答案 0 :(得分:1)

将UILongPressGestureRecognizer添加到TableView,然后使用此代码作为您的操作。

void HandleLongPress (UILongPressGestureRecognizer longPressGesture)
{
    var point = longPressGesture.LocationInView (yourTableView);

    var indexPath = yourTableView.IndexPathForRowAtPoint (point);

    if (indexPath == null)
    {
        System.Console.WriteLine ("Long press on table view, not row.");
    }
    else if (longPressGesture.State == UIGestureRecognizerState.Began)
    {
        System.Console.WriteLine ($"Long press on row, at {indexPath.Row}");
    }
}

这应该有用。

答案 1 :(得分:0)

在.xaml.cs文件中添加以下方法,您将在长按选择中获得所选行的indexPath

public override void RowSelected(UITableView tableView,NSIndexPath indexPath) {     UIAlertController okAlertController = UIAlertController.Create(“Row Selected”,tableItems [indexPath.Row],UIAlertControllerStyle.Alert);     okAlertController.AddAction(UIAlertAction.Create(“OK”,UIAlertActionStyle.Default,null));     ...

tableView.DeselectRow (indexPath, true);

}