使用参数从另一个类调用方法
我在使用参数调用另一个类的方法时遇到了一些问题。 几周以来我一直在编程 objC。
我的目标是在另一个类中加载一个方法,称为:
- (void) openTheCamera:(UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info {
我正在这样调用一个不带参数的方法:
[theOtherClassname theOtherMethod];
但如何使用参数调用它? 我试过:
[theOtherClassname openTheCamera:(UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info];
我认为这是错误的。我怎样才能做对呢?
I have a little problem with calling a method from another class with parameters.
I am programming since a few weeks objC.
My aim is to load in another class a method, called:
- (void) openTheCamera:(UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info {
I am calling a method without parameters this way:
[theOtherClassname theOtherMethod];
But how can I call it with parameters?
I have tried:
[theOtherClassname openTheCamera:(UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info];
I think that's wrong. How can I do it right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该按预期工作,但类型说明符是不必要的,甚至可能有害,因为您类型转换
reader
到UIImagePickerController *
和info
到NSDictionary *
。这很糟糕,因为如果您的输入参数属于您的方法不期望的类型,编译器不会通知您。您可以简单地执行以下操作:
should work as expected, but the type specifiers are unnecessary and can be even harmful, because you type-cast
reader
toUIImagePickerController *
andinfo
toNSDictionary *
. This is bad, because the compiler won't notify you if your input parameters are of a type that your method does not expect.You can simply do:
您可以轻松使用协议:
http:// developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html
在此站点中搜索。你可以找到类似的问题...
You can use easily protocols:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html
Search in this site. you could able to find similar questions...