Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# uipopover控制器正在解除monotouch的分配_C#_Ios_Xamarin.ios_Garbage Collection_Uipopover - Fatal编程技术网

C# uipopover控制器正在解除monotouch的分配

C# uipopover控制器正在解除monotouch的分配,c#,ios,xamarin.ios,garbage-collection,uipopover,C#,Ios,Xamarin.ios,Garbage Collection,Uipopover,我想,我遇到了一个问题,uipopcovercontroller在被解除之前被解除分配,这很奇怪,因为uipopcovercontroller是一个类变量。任何帮助都将不胜感激 这里是错误,我得到了 MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSGenericException Reason: -[UIPopoverController dealloc] reached while

我想,我遇到了一个问题,
uipopcovercontroller
在被解除之前被解除分配,这很奇怪,因为uipopcovercontroller是一个类变量。任何帮助都将不胜感激

这里是错误,我得到了

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSGenericException Reason: -[UIPopoverController dealloc] reached while popover is still visible.
  at at (wrapper managed-to-native) MonoTouch.Foundation.NSObject:monotouch_release_managed_ref (intptr)
  at MonoTouch.Foundation.NSObject.ReleaseManagedRef () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:99
  at MonoTouch.Foundation.NSObject+NSObject_Disposer.Drain (MonoTouch.Foundation.NSObject ctx) [0x00062] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSObject2.cs:602
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at Lab_assistant.Application.Main (System.String[] args) [0x00008] in /working/Lab_assistant/Main.cs:17
这是我正在学习的课程

using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace Lab_assistant
{
[Register("ViewView")]
public class ViewView:UIView
{
    public  Block _b { set; get;}
    public EventHandler _touched;
    private UIView _popViewText;
    private UIViewController _Controller;
    private UIPopoverController _popUp;
    Boolean edit;

    public ViewView (Block b,BlockManger.Del TheMethod)
    {
        _b = b;
        this.Frame = b._location;
        this.BackgroundColor = UIColor.White;
        this.AddGestureRecognizer (new UILongPressGestureRecognizer (tapped));
        TheMethod (_b,this);
        this.Frame = new System.Drawing.RectangleF(b._location.Location, new System.Drawing.SizeF (b._location.Width, b._location.Height + 2));
    }

    [Export("tapped")]
    protected void tapped(UIGestureRecognizer sender)
    {
        TouchOccoured ();
    }

    public void Edit()
    {
        UIButton btn = new UIButton (UIButtonType.RoundedRect);
        _popViewText = new UIView(new System.Drawing.RectangleF(new System.Drawing.PointF(0,0), new System.Drawing.SizeF(200,200)));
        _popViewText.BackgroundColor = UIColor.DarkGray;
        btn.Hidden = false;
        btn.Frame = new System.Drawing.RectangleF(new System.Drawing.PointF(0,31),new System.Drawing.SizeF(100,30));
        btn.SetTitle ("Remove", UIControlState.Normal);

        UIButton btn2 = new UIButton (UIButtonType.RoundedRect);
        btn2.Hidden = false;
        btn2.Frame = new System.Drawing.RectangleF(new System.Drawing.PointF(0,0),new System.Drawing.SizeF(100,30));
        btn2.SetTitle ("Resize", UIControlState.Normal);

        _popViewText.AddSubview (btn);
        _popViewText.AddSubview (btn2);
        _Controller = new UIViewController ();
        _Controller.Add (_popViewText);
        _popUp = new UIPopoverController(_Controller);

        btn.TouchUpInside += (object sender, EventArgs e) => 
        {
            this.RemoveFromSuperview(); 
            edit = false;
        };
    }

    public void EditBlock()
    {
        if (!edit)
        {
            edit = true;
            _popUp.PopoverContentSize = new SizeF (200, 200);
            _popUp.PresentFromRect (new System.Drawing.RectangleF (new PointF(0,0), new System.Drawing.SizeF (20, 20)), this, UIPopoverArrowDirection.Left, true);
            //_popViewText = new UIView (rec);
        }
    }

    public void TouchOccoured()
    {
        if(_touched != null)
        {
            this.Edit ();
            this.EditBlock ();

            _touched (this, null);
        }
    }
}
}
非常感谢您的帮助

以下是一些想法:

  • 确保只调用一次
    Edit
  • 确保未释放视图(通过实现Dispose重载并在其中放置断点或Console.WriteLine,可以轻松地执行此操作)

I bet
Edit
被多次调用,导致多个
UIPopoverController
被实例化。如果是这样的话,你可以用这样的方法来修复它:

公共作废编辑()
{
if(_popup!=null&&u popup.popopovervisible){
_弹出。驳回(假);
_popup.Dispose();
}
//你的代码
}

非常感谢,由于长按手势,我正在调用edit,这导致它被多次调用