将 NSArray 与 Monotouch 结合使用
如何在 C# (Monotouch) 中将项目插入 NSArray 对象?我没有找到合适的方法来做到这一点?在 Objective-C 端,有一个名为“initWithObjects”的构造函数,但我在 C# 端没有找到它。
聚甲醛
How to insert items into NSArray object in C# (Monotouch)? I don't find appropriate method to do so? In Objective-C side, there is a constructor called "initWithObjects" but I don't find this on C# side.
pom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很抱歉用问题来回答您的问题,但是您确定要创建 NSArray 吗?
我问这个问题是因为 MonoTouch 在幕后做了一些工作,这样您就不必处理 NSArray 了。
如果您转到 MonoTouch API 设计页面 并在页内搜索“NSArray”,您'会发现这个:
换句话说,除非你有特定的理由,否则你不必搞乱 NSArray。
但是,如果您确实有理由,或者这是您的偏好,那么 Jason 的答案是正确的:
我唯一要补充的是,如果您是 Objective-C 开发人员并给予 MonoTouch尝试一下,你已经习惯了:
区别在于 Objective-C 版本末尾的“nil”。 MonoTouch 的 NSArray 没有同样的要求。你只需将你想要它包含的对象传递给它,它就会愉快地这样做。不需要终止 null :)
希望这有帮助......
Sorry to answer your question with a question, but are you sure you want to create an NSArray?
I ask because MonoTouch does some work behind the scenes so that you don't have to deal with NSArray.
If you go to the MonoTouch API Design page and do an in-page search for "NSArray", you'll find this:
In other words, unless you have a specific reason to, you don't have to mess with NSArray.
But, if you do have a reason, or if it's your preference, then Jason's answer is correct:
The only thing I'd add is that, if you're an Objective-C dev and giving MonoTouch a try, you're used to this:
The difference is the "nil" at the end of the Objective-C version. MonoTouch's NSArray doesn't have this same requirement. You just pass it the objects you want it to contain, and it happily does so. No terminating null required :)
Hope this helps...
我没有使用 Monotouch - 但如果你想操作 NSArray,你会想要使用它的近亲 NSMutableArray。
I'm not using Monotouch - but if you're looking to manipulate an NSArray, you're going to want to use it's cousin, NSMutableArray.
看起来这个静态方法就是你想要的:
像这样使用:
It looks like this static method is what you want:
Used like this: