使用参数从另一个类调用方法

发布于 2024-10-15 02:31:31 字数 511 浏览 1 评论 0原文

我在使用参数调用另一个类的方法时遇到了一些问题。 几周以来我一直在编程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2024-10-22 02:31:31
[theOtherClassname openTheCamera:(UIImagePickerController*) reader 
didFinishPickingMediaWithInfo: (NSDictionary*) info];

应该按预期工作,但类型说明符是不必要的,甚至可能有害,因为您类型转换 readerUIImagePickerController *infoNSDictionary *。这很糟糕,因为如果您的输入参数属于您的方法不期望的类型,编译器不会通知您。

您可以简单地执行以下操作:

[theOtherClassname openTheCamera:reader didFinishPickingMediaWithInfo:info];
[theOtherClassname openTheCamera:(UIImagePickerController*) reader 
didFinishPickingMediaWithInfo: (NSDictionary*) info];

should work as expected, but the type specifiers are unnecessary and can be even harmful, because you type-cast reader to UIImagePickerController * and info to NSDictionary *. 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:

[theOtherClassname openTheCamera:reader didFinishPickingMediaWithInfo:info];
狼性发作 2024-10-22 02:31:31

您可以轻松使用协议:

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文