C# 从Xamarin绑定调用UIKit方法
我的Xamarin项目有一个广告SDK绑定。绑定在这里: 我的问题来自于方法:C# 从Xamarin绑定调用UIKit方法,c#,ios,xamarin.ios,xamarin,uikit,C#,Ios,Xamarin.ios,Xamarin,Uikit,我的Xamarin项目有一个广告SDK绑定。绑定在这里: 我的问题来自于方法: [Export("adMarvelViewFrame")] RectangleF AdMarvelViewFrame(); 在我的课堂上,我是这样实施的: [Export("adMarvelViewFrame")] public RectangleF AdMarvelViewFrame() { return new RectangleF(0.0f, 0.0f, UIScreen.MainScreen.Bou
[Export("adMarvelViewFrame")]
RectangleF AdMarvelViewFrame();
在我的课堂上,我是这样实施的:
[Export("adMarvelViewFrame")]
public RectangleF AdMarvelViewFrame()
{
return new RectangleF(0.0f, 0.0f, UIScreen.MainScreen.Bounds.Width, 250.0f);
}
但是,当视图加载时,我得到错误:
UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
我(想)我理解这个错误的含义,但是当本地代码在其他地方调用它时,我如何在主线程上调用它?您调用的UIKIt方法是UIScreen.MainScreen 简单的解决方法是在类变量中预取UIScreen.MainScreen,并在AdMarvelViewFrame中使用该类变量