调用 Objective C 中的协议方法
我在类的 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 来调用这些方法吗?
i have used the following protocol in the yyyy.h file of a class
@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
and i am calling these methods using the delegate object
NSObject < FGalleryViewControllerDelegate> *_photoSource;
in some other class not in yyy.m,,
now i tried to call these methods in the same class yyy.m,,i used the same delegate object to call the methods but its crashed ,,should i use self to call those?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望自己调用它们,请设置此委托对象的@property。然后使用它就可以了。
if you want self to call those then set the @property of this delegate object. and then use it it works.