gpt4 book ai didi

iphone - 调用 Objective C 中的协议(protocol)方法

转载 作者:行者123 更新时间:2023-12-03 21:18:37 25 4
gpt4 key购买 nike

我在类的 yyyy.h 文件中使用了以下协议(protocol)

 @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

我使用委托(delegate)对象调用这些方法

NSObject < FGalleryViewControllerDelegate> *_photoSource;

在 yyy.m 之外的其他类(class)中,,

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

最佳答案

如果您希望自己调用它们,请设置此委托(delegate)对象的@property。然后使用它就可以了。

关于iphone - 调用 Objective C 中的协议(protocol)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7453595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com