在目标c中调用协议方法

时间:2011-09-17 08:44:17

标签: iphone objective-c xcode ios4 protocols

我在类

的yyyy.h文件中使用了以下协议
 @protocol FGalleryViewControllerDelegate

    @required
    - (int)numberOfPhotosForPhotoGallery:(FGalleryViewController*)gallery;
    - (FGalleryPhotoSourceType)photoGallery:(FGalleryViewController*)gallery sourceTypeForPhotoAtIndex:(NSUInteger)index;

    @optional
    - (NSString*)photoGallery:(FGalleryViewController*)gallery captionForPhotoAtIndex:(NSUInteger)index;

    // the photosource must implement one of these methods depending on which FGalleryPhotoSourceType is specified 
    - (NSString*)photoGallery:(FGalleryViewController*)gallery filePathForPhotoSize:(FGalleryPhotoSize)size atIndex:(NSUInteger)index;
    - (NSString*)photoGallery:(FGalleryViewController*)gallery urlForPhotoSize:(FGalleryPhotoSize)size atIndex:(NSUInteger)index;

    @end

我正在使用委托对象

调用这些方法
NSObject < FGalleryViewControllerDelegate> *_photoSource;

在其他一些不在yyy.m中的课程中

现在我试着在同一个类yyy.m中调用这些方法,我使用相同的委托对象来调用方法但是它崩溃了,我应该使用self来调用它们吗?

1 个答案:

答案 0 :(得分:0)

如果你想让self调用那些,那么设置这个委托对象的@property。然后使用它有效。