我無法找到此調用的綁定。在下面的示例中,我爲PerformSelector添加了自己的重載。也許其中一個Xamarin工程師可以證實這一點。
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.ObjCRuntime;
using System.Runtime.InteropServices;
namespace delete20120506
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
//
Target target = new Target();
NSUrl url = new NSUrl ("http://xamarin.com/");
NSData nsData = NSData.FromString ("Hello");
target.PerformSelector (new MonoTouch.ObjCRuntime.Selector
("TestSelUrl:withData:"), url, nsData);
window.MakeKeyAndVisible();
return true;
}
}
[Register ("Target")]
public class Target : NSObject
{
public Target() : base (NSObjectFlag.Empty) {}
[Export("TestSelUrl:withData:")]
void TestSelUrlWithData(NSUrl url, NSData nsData)
{
Console.WriteLine ("In TestSelUrlWithData");
Console.WriteLine (url.ToString());
Console.WriteLine (nsData.ToString());
return;
}
[DllImport ("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern void void_objc_msgSend_intptr_intptr_intptr (IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2, IntPtr arg3);
[DllImport ("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSendSuper")]
public static extern void void_objc_msgSendSuper_intptr_intptr_intptr (IntPtr receiver, IntPtr selector, IntPtr arg1, IntPtr arg2, IntPtr arg3);
public virtual void PerformSelector (MonoTouch.ObjCRuntime.Selector sel,
NSObject arg1, NSObject arg2)
{
if (this.IsDirectBinding)
{
void_objc_msgSend_intptr_intptr_intptr (this.Handle,
Selector.GetHandle ("performSelector:withObject:withObject:"),
sel.Handle, arg1.Handle, arg2.Handle);
}
else
{
void_objc_msgSendSuper_intptr_intptr_intptr (this.SuperHandle,
Selector.GetHandle ("performSelector:withObject:withObject:"), sel.Handle,
arg1.Handle, arg2.Handle);
}
}
}
}
謝謝你的徹底答案mhutch。當我需要釋放主線程以使可可重新繪製屏幕時,我一直在使用PerformSelector,然後我可以重新處理一些邏輯。現在我正試圖更新一個進度條的等價物,這個進度條在writeStream for循環中已經繪製到屏幕上。想要看看我是否可以通過在for循環中添加一個執行選擇器並更新進度條的屬性來刷新屏幕。 –
另一種方法是使用邏輯/流的線程,並使用線程中的InvokeOnMainThread來更新UI。 –
這使我不必手動重新綁定庫,因爲原始開發人員沒有綁定特定的屬性,也沒有釋放源,所以謝謝。對於任何感興趣的人,可以通過調用setColor使用msgSend_IntPtr_IntPtr方法輕鬆設置屬性:其中color是屬性的名稱。 (Arg 0是屬性值,Arg 1 = IntPtr.Zero) – Dermot