Xamarin.ios 正在获取已在进行的模式转换的异常,?

Xamarin.ios 正在获取已在进行的模式转换的异常,?,xamarin.ios,Xamarin.ios,注意:我使用的是MonoTouch 当我第二次单击tbName(textfield,请参见下面的委托)时,出现以下异常。第一次出现模态视图时没有问题,我将其忽略(下面也提供了代码)。但是当我第二次点击tbName(顺便说一下Textfield)时,我得到了一个例外: “引发了Objective-C异常。名称:NSInternalInconsistencyException原因:在转换已在进行的情况下,尝试成为从到的模式转换。等待ViewDidDisplay/ViewDidEnglish以知道当前

注意:我使用的是MonoTouch

当我第二次单击tbName(textfield,请参见下面的委托)时,出现以下异常。第一次出现模态视图时没有问题,我将其忽略(下面也提供了代码)。但是当我第二次点击tbName(顺便说一下Textfield)时,我得到了一个例外:

“引发了Objective-C异常。名称:NSInternalInconsistencyException原因:在转换已在进行的情况下,尝试成为从到的模式转换。等待ViewDidDisplay/ViewDidEnglish以知道当前转换已完成”

但问题是,我在点击前等待的时间并不重要,所以我认为我缺少了一个基本点

From the NewEnvelopeViewController class:
public override void ViewDidAppear (bool animated)
   {
        base.ViewDidAppear (animated);

    tbName.TouchDown += delegate(object sender, EventArgs e) {
    // Set everything up for the editting of the envelope's name
        _dataViewController.NumericPad = false;
        _dataViewController.FieldType = NewEnvelopeDataViewController.Fields.Name;
        _dataViewController.EnvelopeToEdit = _envelope;

        this.PresentModalViewController(_dataViewController, true);
    };

From the NewEnvelopeDataViewController class:
公共覆盖无效视图显示(布尔动画) { base.viewdid显示(动画)


我曾看过一篇关于StackOverflow的文章,内容是关于如何使用DidAspect进行操作,但在我的案例中,它似乎不起作用,也不清楚到底是什么问题(而不仅仅是修补问题)。

移动以下代码

tbName.TouchDown += delegate(object sender, EventArgs e) {
    // Set everything up for the editting of the envelope's name
        _dataViewController.NumericPad = false;
        _dataViewController.FieldType = NewEnvelopeDataViewController.Fields.Name;
        _dataViewController.EnvelopeToEdit = _envelope;

        this.PresentModalViewController(_dataViewController, true);
    };
从ViewDidAppear方法到ViewDidLoad方法。ViewDidAppear在每次视图出现时都会被触发,包括当模式视图控制器被解除时。因此,您的代码现在正在做的是向对象的触地事件添加另一个处理程序,因此当它被触发时,它总是会执行一个或多个extr一次,导致多次显示相同的模态视图控制器。这就是为什么它第一次工作,但第二次崩溃


一般来说,如果您想订阅ViewDidDisplay中的事件,请确保在ViewDidEnglish中取消订阅它们,或者更好的是,始终在ViewDidLoad中订阅事件,并在ViewDidUnload中取消订阅。

在再次显示模式控制器之前,您是否要解除它?否。我只在上面显示的“完成”和“取消”单击事件中解除订阅,并且我把断点放在那里。它在这个。PresentModalViewController(_dataViewController,true);行。还有其他想法吗?非常感谢!现在我了解了更多!
tbName.TouchDown += delegate(object sender, EventArgs e) {
    // Set everything up for the editting of the envelope's name
        _dataViewController.NumericPad = false;
        _dataViewController.FieldType = NewEnvelopeDataViewController.Fields.Name;
        _dataViewController.EnvelopeToEdit = _envelope;

        this.PresentModalViewController(_dataViewController, true);
    };