如何使用MonoTouch
??
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000
@interface NSObject (SubscriptingSupport)
- (id)objectAtIndexedSubscript:(NSUInteger)idx;
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key;
- (id)objectForKeyedSubscript:(id)key;
@end
#endif
尝试了以下Documentation,但没有运气
[BaseType (typeof (NSObject)), Bind ("NSObject")]
public interface NSObject2
{
[Bind("objectAtIndexedSubscript:")]
NSObject ObjectAtIndexedSubscript (uint idx);
[Bind("setObject:atIndexedSubscript:")]
void SetObjectAtIndexedSubscript (NSObject obj, uint idx);
[Bind("setObject:forKeyedSubscript:")]
void SetObjectForKeyedSubscript (NSObject obj, NSObject key);
[Bind("objectForKeyedSubscript:")]
NSObject ObjectForKeyedSubscript (NSObject key);
}
它提供了大量错误,如
错误CS0115:`DocParser.Dispose(bool)'被标记为覆盖但是 找不到合适的方法来覆盖(CS0115)
提前致谢
亚历。
答案 0 :(得分:1)
绑定工具不支持为核心类的扩展生成存根。
好消息是,从根本上说,工作非常简单:你必须向实例NSObject的对象发送消息。
这意味着您可以手动编写代码:
void GetObjectAtIndex (NSObject target, int objectAt)
{
Runtime.GetNSObject (Messaging.objc_msgSend_int (target.Handle, Selector.GetHandle ("objectAtIndexedSubscript:", objectAt));
}
上述手工编写可能很麻烦,因此您可以在虚构类上运行生成器,然后将结果复制/粘贴到您自己的类中,该类采用参数“NSObject target”,如上所示。
答案 1 :(得分:0)
我认为你需要保持类名相同,只要你在MonoTouch.Foundation
之外有一个不同的命名空间:
namespace WhateverNamespaceYouWantBesidesMonoTouch.Foundation
{
[BaseType (typeof (MonoTouch.Foundation.NSObject))]
public interface NSObject
{
[Export("objectAtIndexedSubscript:")]
MonoTouch.Foundation.NSObject ObjectAtIndexedSubscript (uint idx);
[Export("setObject:atIndexedSubscript:")]
void SetObjectAtIndexedSubscript (MonoTouch.Foundation.NSObject obj, uint idx);
[Export("setObject:forKeyedSubscript:")]
void SetObjectForKeyedSubscript (MonoTouch.Foundation.NSObject obj, MonoTouch.Foundation.NSObject key);
[Export("objectForKeyedSubscript:")]
MonoTouch.Foundation.NSObject ObjectForKeyedSubscript (MonoTouch.Foundation.NSObject key);
}
}
我也不确定[绑定]是什么,你应该使用[导出]。