开发者

Call method from another class with parameters

开发者 https://www.devze.com 2023-02-07 11:09 出处:网络
I have a little problem with calling a method from another class with parameters. I am programming since a few wee开发者_Python百科ks objC.

I have a little problem with calling a method from another class with parameters. I am programming since a few wee开发者_Python百科ks 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?


[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];


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

0

精彩评论

暂无评论...
验证码 换一张
取 消