Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以单触方式绑定这些?_C#_Objective C_Xamarin.ios - Fatal编程技术网

C# 如何以单触方式绑定这些?

C# 如何以单触方式绑定这些?,c#,objective-c,xamarin.ios,C#,Objective C,Xamarin.ios,下面的ObjectiveC代码如何转换为MonoTouch @interface PSPDFBookmarkViewController : UITableViewController <PSPDFStyleable> - (instancetype)initWithDocument:(PSPDFDocument *)document; @property (nonatomic, weak) id<PSPDFBookmarkViewControllerDelegate>

下面的ObjectiveC代码如何转换为MonoTouch

@interface PSPDFBookmarkViewController : UITableViewController <PSPDFStyleable>
- (instancetype)initWithDocument:(PSPDFDocument *)document;
@property (nonatomic, weak) id<PSPDFBookmarkViewControllerDelegate> delegate;
@property (nonatomic, assign) BOOL isInPopover;
@end
那么这个界面呢

@interface PSPDFBookmarkViewController (SubclassingHooks)
- (void)createBarButtonItems;
@end

(SubclassingHooks)
是关于什么的,它的C#表亲是什么?

很多问题。。。以下是一些答案:

ObjectiveC
init*
选择器是.NET构造函数。因此:

- (instancetype)initWithDocument:(PSPDFDocument *)document;
应该是:

[Export ("initWithDocument:")]
IntPtr Constructor (PSPDFDocument document);
您的其他C#绑定缺少其
[Export]
属性。例如

[Export ("isInPopover")]
bool IsInPopover { get; set; }
其他问题:

是一个Objective-C协议,与.NET接口非常相似。现在,如果不需要
pspdfstylable
,则不必绑定它

什么是
id

这是一个实现
PSPDFBookmarkViewControllerDelegate
的实例。对于
委托
属性,您通常会将其绑定为
PSPDFBookmarkViewControllerDelegate
,并添加
WeakDelegate
,以便可以使用实现正确选择器的任何
NSObject
。例如

[Export ("delegate", ArgumentSemantic.Assign)][NullAllowed]
NSObject WeakDelegate { get; set; }

[Wrap ("WeakDelegate")]
PSPDFBookmarkViewControllerDelegate Delegate { get; set; }
您需要将
Delegates=newstring[]{“WeakDelegate”}
添加到
[BaseType]
属性中。如果要将代理成员转换为事件,还可以添加
Events=
。例如

[BaseType (typeof (UITableViewController), Delegates=new string [] { "WeakDelegate" }, Events=new Type [] {typeof (PSPDFBookmarkViewControllerDelegate)})]
(SubclassingHooks)
是一个Objective-C类别,与.NET扩展方法非常相似。这需要对现有生成器进行一些手动绑定


最后,请确保阅读Xamarin文档门户上提供的。它不是很复杂(您的示例只需几行就可以访问很多案例),但是有很多数据需要消化(如果您不太了解Objective-C,则需要消化更多数据)。

正确。我知道,但我忘了打字。这份报告是有价值的信息。遗骸:什么是身份证?如何处理PSPDStyleable协议?最后:如何绑定类别(子类钩子)?很多,我知道…又找到了一个。类别=类扩展。这里包括:@Krumelur我用了更多的细节来解释我最初的答案,但是你找到了可以解释所有问题的链接(更深入)。确实有很多特殊情况……我现在感觉有点迷茫。我甚至没有试着去理解像“[Export”(“delegate”,ArgumentSemantic.Assign)]”或“[PostGet”(“Documents”)]”这样的东西。离完美还有很长的路要走。但最终一切都会成功。
[BaseType (typeof (UITableViewController), Delegates=new string [] { "WeakDelegate" }, Events=new Type [] {typeof (PSPDFBookmarkViewControllerDelegate)})]