2015-11-06 86 views
2

我想實現一個NSWebView代表,但是當我運行它,我得到這個錯誤:objc.signature記錄在哪裏?

TypeError: Error when calling the metaclass bases 
    class Delegate does not correctly implement protocol WebScripting: the signature for method isSelectorExcludedFromWebScript: is [email protected]:: instead of [email protected]:: 

我在哪裏可以找到文檔「C @ ::」,而不是「Z @ ::',以及我的代碼可能有什麼問題?

問題的方法如下:

def isSelectorExcludedFromWebScript_(self, sel): 
    return True 

具體來說,NSWebView在記載:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/index.html(但我懷疑,蘋果將移動在未來的這個URL),更確切地說

,委託的我嘗試使用的非正式協議記錄在此處:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebFrameLoadDelegate_Protocol/index.html#//apple_ref/doc/uid/TP40003828https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebScripting_Protocol/index.html#//apple_ref/doc/uid/TP40001562

我發現的objc.signature的唯一文檔是:http://pythonhosted.org/pyobjc/api/module-objc.html

+0

從本質上講,我的確看過http://pseudofish.com/showing-a-nssavepanel-as-a-sheet.html,但似乎*蘋果開發文檔的每一個鏈接都被破壞*。在蘋果公司恥辱。 – Arafangion

+0

我能夠[在這裏](https://developer.apple.com/library/mac/navigation/)搜索NSSavePanel。但是,NSWebView沒有返回任何結果,也沒有objc.signature,也沒有選擇器從WebWebScript。不好的搜索算法,不完整的文檔或API發生了顯着變化。 –

+0

@BaconBits:我已經在問題中提供了明確的參考 - 謝謝。 :) – Arafangion

回答

2

標準的Objective-C類型編碼記錄在Apple's ObjC runtime reference中。這定義爲cchar,@爲對象,:爲選擇器,但未提及Z

PyObjc通過引用objc模塊中的一堆常量,在http://pythonhosted.org/pyobjc/api/module-objc.html#objective-c-type-strings中添加了一些不在該列表中的列表。 objc._C_NSBOOL的值爲Z(在pyobjc BridgeSupport docs也提到)

所以它看起來像問題與Python的True的正確目標C型的轉換做的,但我不知道如何解決這個問題。

+0

這是一個富有洞察力的迴應。我試圖指定選擇器簽名,但我似乎無法正確執行此操作。我不確定該#type-encodings部分是否描述簽名類型,因爲它沒有提及'c'。然而,我想知道,如果它與這個特定的方法是一個_class_方法而不是一個實例方法有關。 – Arafangion

+0

http://pythonhosted.org/pyobjc/api/module-objc.html#objective-c-type-strings中有另一個參考,它用'objc'模塊中定義的常量來描述這些字符串。 'objc._C_BOOL'是'c','objc._C_NSBOOL'是'Z'。 –

+0

現在實際上開始有些意義了,我沒有想到要看那些常量的值。我希望能夠解決如何糾正我所遇到的問題,但就目前而言,看起來你還可能贏得獎金。 :)(特別是如果你把涉及objc._C_NSBOOL的評論正確地加入到答案中) – Arafangion