如何使用自我调用方法[self Method_Name];当方法名称非常长时 - (void)imagePickerController:(UIImagePickerController *)

时间:2012-07-05 06:03:48

标签: iphone objective-c ios xcode

我是iPhone开发的新手。我想知道如何使用self调用方法,如:

[self Method_Name];

当方法名称很长时

- (void)imagePickerController: (UIImagePickerController *)picker
        didFinishPickingImage: (UIImage *)image
                  editingInfo: (NSDictionary *)editingInfo
{
    ...
}

W想要使用imagePickerController来调用self方法。我试着用它来调用它:

 [self imagePickerController]; // Crash Here

但代码总是在这一行崩溃。我该如何调用该方法?

5 个答案:

答案 0 :(得分:3)

imagePickerController不是方法名称。方法名称是

imagePickerController: didFinishPickingImage:  editingInfo: 

它有三个参数,你必须传递参数。

当您在同一个类中调用方法时,您可以编写如下

[self imagePickerController: pickerParameter
    didFinishPickingImage: imageParameter
    editingInfo: editingInfoParameter];

答案 1 :(得分:2)

[self imagePickerController: pickerParameter
    didFinishPickingImage: imageParameter
    editingInfo: editingInfoParameter];

xxxParameters是您要传递给方法的参数。

答案 2 :(得分:2)

这将自动调用。 但回答关于如何调用此类方法的问题,应该像

那样完成
[self imagePickerController: picker
didFinishPickingImage: image
editingInfo: editingInfo];

但不需要调用此委托方法。它自动调用

希望它有所帮助。快乐的编码:)

答案 3 :(得分:2)

如果您正在调用[self method_name]之类的方法。然后方法应该在该类的(.h)文件中声明(如果你想在另一个类中访问此方法,否则不需要在.h中声明),并且该方法应该在同一类的(.m)文件中定义。你可以调用这样的任何方法..

// in .h file

- (void)imagePickerController: (UIImagePickerController *)picker
didFinishPickingImage: (UIImage *)image
editingInfo: (NSDictionary *)editingInfo;

// cal this in .m as following  

[self imagePickerController:pickerController
didFinishPickingImage: imageNamed
editingInfo: editDictionary ];

答案 4 :(得分:1)

编写方法.m文件的定义如下:

    #import "classname.h"

    @implementation classname

    @synthesis variable1 = <variable1_>;

    @synthesis .....;

    -(void)imagePickerController: (UIImagePickerController *)picker
    didFinishPickingImage: (UIImage *)image
    editingInfo: (NSDictionary *)editingInfo {

      // Your code for this method comes here.

    }

(无需在.h文件中声明方法。)

然后在需要的地方使用“self”调用方法,如下所示:

    [self imagePickerController: UIImagePickerControllerObject
    didFinishPickingImage: UIImageObject
    editingInfo: NSDictionaryObject];