2013-10-07 2 views
1

제가 생각하기에, UHPopoverController가 클래스 변수이므로 이상한 경우 UIPopoverController이 해제되기 전에 문제가 발생합니다. 어떤 도움이라도 대단히 감사 할 것입니다. 여기 uipopover 컨트롤러가 단선 해제되었습니다.

, 나는

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); 
     } 
    } 
} 
} 

에 수업하고 있어요되어 도움

답변

2

나는 Edit이 여러 번 호출되어 다중 UIPopoverController이 인스턴스화되는 결과입니다. 그럴 경우 다음과 같이 수정하면됩니다.

public void Edit() 
{ 
    if (_popup != null && _popup.PopoverVisible) { 
     _popup.Dismiss (false); 
     _popup.Dispose(); 
    } 

    //your code 
} 
+0

고맙습니다. 긴 편집 결과를 여러 번 호출하게되어서 고맙습니다. –

1

몇 주셔서 대단히 감사합니다 아이디어 :

  • Edit은 한 번만 호출됩니다.
  • ViewView도 삭제되어 있지 않은지 확인하십시오. Dispose 오버로드를 구현하고 중단 점 또는 Console.WriteLine을 입력하여이를 쉽게 수행 할 수 있습니다.