English 中文(简体)
为什么我的UIPicker View 选择时崩溃
原标题:Why does my UIPickerView crashing when selecting

我在 github < a href="https://github.com/Nytrm/TextfieldUIPickerView"上创建了一个样本, rel=“ no follow” > Github 链接

当点击一行或试图在 UIPickerView 中滚动时, 它会崩溃, 我想知道为什么 。

// create a ActionSheet
var actionPickerSheet = new UIActionSheet("Select a Category");
actionPickerSheet.Style = UIActionSheetStyle.BlackTranslucent;
// Create UIpickerView
var catPicker = new UIPickerView(){
    Model = new catPickerModel(),
    AutosizesSubviews = true,
    Hidden = false,
    ShowSelectionIndicator = true
};
// show inside view and add the catPicker as subView
actionPickerSheet.ShowInView(View);
actionPickerSheet.AddSubview(catPicker);
// resize both views so it fits smoothly
actionPickerSheet.Frame = new RectangleF(0,100,320,500);
catPicker.Frame = new RectangleF(actionPickerSheet.Frame.X,actionPickerSheet.Frame.Y-25,actionPickerSheet.Frame.Width, 216);

和模型

private class catPickerModel : UIPickerViewModel
{
    public string[] protocolNames = new string[]
    {
        "Web", "Phone Call", "Google Maps", "SMS", "Email"
    };

    public override int GetComponentCount(UIPickerView uipv)
    {
        return 1;
    }

    public override int GetRowsInComponent( UIPickerView uipv, int comp)
    {
        //each component has its own count.
        int rows = protocolNames.Length;
        return(rows);
    }

    public override string GetTitle(UIPickerView uipv, int row, int comp)
    {  
        //each component would get its own title.
        return protocolNames[row];
    }

    public override void Selected(UIPickerView uipv, int row, int comp)
    {
        Console.WriteLine("selected:" + row);
    }

    public override float GetComponentWidth(UIPickerView uipv, int comp)
    {
        return 300f;
    }
}

我不知道为什么它不断崩溃, 是某种方法我错过了 在模型还是我试图这样做 以错误的方式?

谢谢 谢谢

最佳回答

尝试将您的 catPicker 设置为该类的私人变量 :

namespace TextfieldUIPickerView
{
    public partial class TextfieldUIPickerViewViewController : UIViewController
    {
        private UIPickerView catPicker;
 ...

看来GC已经收集了你的猫Picker 并处置了它

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签