首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin iOS (9.2):手势在模拟器中不起作用

Xamarin iOS (9.2):手势在模拟器中不起作用
EN

Stack Overflow用户
提问于 2016-01-29 16:19:21
回答 1查看 505关注 0票数 1

有人能解释一下我的代码不能工作的原因吗?我尝试在iOS中创建一个多选UIPicker,方法是将UITableViewCell添加到UIPickerModel中的View,然后将UITapGestureRecognizer添加到每个单元格。

但是模拟器对我的触摸板上的任何点击都没有反应。

代码如下:

代码语言:javascript
复制
class PickerDataModel : UIPickerViewModel
{
    /*
    <summary>
        the items we wish to display
    </summary>
    */
    public List<string> Items { get; private set; }

    public PickerDataModel()
    {
        Items = new List<string>();
    }

    /*
    <summary>
        called by the picker to get the number of spinner items
    </summary>
    */    
    public override nint GetRowsInComponent(UIPickerView picker, nint component)
    {
        return Items.Count;
    }

    /* <summary>called by the picker to get the number of spinner items</summary> */    
    public override nint GetComponentCount(UIPickerView picker)
    {
        return 1;
    }

    /* <summary>called when a row is selected in the spinner</summary> */
    public override void Selected(UIPickerView picker, nint row, nint component)
    {

    }

    /* 
    <summary>
        Custom row view.
        The view param is the reusable view for the row. It will be null initially.

        You can add subviews or do anything within the view. But a lazy-initialization 
        block is preferred rather than every time this method is called.

        **Note** GetTitle() is no longer overridden since we aren't using 
        the default row view.
    </summary>
    */
    public override UIView GetView(UIPickerView picker, 
                                   nint row, nint component, UIView view)
    {
        if (view == null)
        {
            CGSize rowSize = picker.RowSizeForComponent(component);
            UITableViewCell cell = 
                    new UITableViewCell(new CGRect(new CGPoint(0, 0), rowSize));
            view = cell;
            cell.BackgroundColor = UIColor.Clear;
            cell.UserInteractionEnabled = true;
            UITapGestureRecognizer singleTapGestureRecognizer = 
                                            new UITapGestureRecognizer();
            singleTapGestureRecognizer.AddTarget(() => Console.WriteLine("Tapped"));
            singleTapGestureRecognizer.NumberOfTapsRequired = 1;
            cell.AddGestureRecognizer(singleTapGestureRecognizer);

            cell.TextLabel.Text = Items[(int) row];

            cell.Tag = row;                    
        }
        return view;
    }

    void Test()
    {
        Console.WriteLine("Tapped");
    }

    private void ToggleSelection(UITapGestureRecognizer recognizer)
    {                    
        ((UITableViewCell)recognizer.View).Accessory = UITableViewCellAccessory.Checkmark;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-02-02 23:13:42

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35079806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档