2011-07-01 43 views

回答

4

MonoTouch的所有NS *對象都實現了MonoTouch.ObjCRuntime.INativeObject接口,該接口具有一個名爲「Handle」的屬性getter。該訪問器在NSObject和所有子類上是公共的。

編輯:代碼綁定NSSetUncaughtExceptionHandler()將是這樣的:

public delegate void NSUncaughtExceptionHandler (IntPtr exception); 

[DllImport ("/System/Library/Frameworks/Foundation.framework/Foundation")] 
extern static void NSSetUncaughtExceptionHandler (IntPtr handler); 

然後,你可以使用這樣的:

static void MyUncaughtExceptionHandler (IntPtr exception) 
{ 
    // Got an exception... 
} 

static void Main (string[] args) 
{ 
    NSSetMyUncaughtExceptionHandler (Marshal.GetFunctionPointerForDelegate(
     new NSUncaughtExceptionHandler(
      MyUncaughtExceptionHandler 
     ) 
    ); 
} 
+0

你的建議的問題是,基金會的功能不屬於到任何類型的NSObject。它們更像全球功能。你能給我一個例子,說明如何調用像'NSSetUncaughtExceptionHandler'這樣的函數嗎? –

+0

啊。非常感謝! –

相關問題