2

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

[self Method_Name];

当方法名很长的时候 Like

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

W 想使用 调用 imagePickerController方法self。我试着用以下方式调用它:

 [self imagePickerController]; // Crash Here

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

4

5 回答 5

3

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

imagePickerController: didFinishPickingImage:  editingInfo: 

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

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

[self imagePickerController: pickerParameter
    didFinishPickingImage: imageParameter
    editingInfo: editingInfoParameter];
于 2012-07-05T06:13:29.977 回答
2
[self imagePickerController: pickerParameter
    didFinishPickingImage: imageParameter
    editingInfo: editingInfoParameter];

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

于 2012-07-05T06:07:30.080 回答
2

这将被自动调用。但是回答你关于如何调用这些方法的问题,它应该像

[self imagePickerController: picker
didFinishPickingImage: image
editingInfo: editingInfo];

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

希望能帮助到你。快乐编码:)

于 2012-07-05T06:09:16.710 回答
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 ];
于 2012-07-05T06:12:42.930 回答
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];
于 2012-07-05T06:59:09.567 回答