您的位置:首页 > 产品设计 > UI/UE

you are calling a UIKit method that can only be invoked from the UI thread.

2014-03-04 16:59 453 查看
mono touch开发时长遇到这样的错误: you are calling a UIKit method that can only be invoked from the UI thread.

这是因为,你的代码涉及到MonoTouch.UIKit库中对象,必须通过UI主线程InvokeOnMainThread来处理才行,类似下面的代码段:

using(var pool = new NSAutoreleasePool()) {
    this.InvokeOnMainThread(delegate {
        //...         
    });
}


有时候在并行编程中,通过ui主线程来处理并不能够奏效,这时候需要通过禁用UI线程,这样就不会出错:

var previous = UIApplication.CheckForIllegalCrossThreadCalls;
UIApplication.CheckForIllegalCrossThreadCalls = false;
//....
UIApplication.CheckForIllegalCrossThreadCalls = previous;
注意哦,在mono touch中,UI主线程检查是可选的,并且可以被禁用,无论是全局或局部。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐