gpt4 book ai didi

ios - 自定义委托(delegate)找不到声明

转载 作者:行者123 更新时间:2023-11-29 10:43:58 25 4
gpt4 key购买 nike

我正在创建一个购物 list 应用程序,并尝试在编辑项目时实现自定义委托(delegate)。在头文件底部创建 @protocol 时,尝试在 @interface 部分中声明该协议(protocol)的属性时,出现以下错误:找不到 GEMEditItemViewControllerDelegate 的协议(protocol)声明

这是我的头文件的样子。

#import <UIKit/UIKit.h>
#import "GEMItem.h"

@interface GEMEditItemViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>

@property GEMItem *item;
@property (weak) id<GEMEditItemViewControllerDelegate> delegate;

@end

@protocol GEMEditItemViewControllerDelegate <NSObject>
@required
- (void)controller:(GEMEditItemViewController *)controller didUpdateItem:(GEMItem *)item;
@end // End of delegate protocol

或者在一个单独的实例中,当在 interface 上方声明 protocol 时,我无法访问 View Controller 以作为该声明方法的参数传递。

那个头文件看起来像:

#import <UIKit/UIKit.h>
#import "GEMItemManager.h"

@protocol GEMAddItemViewControllerDelegate <NSObject>
/*
// Tried to add the controller (controller:(GEMAddItemviewController *)controller) as first paramiter, but was getting and errror, so I have omitted it for the time being
- (void)controller:(GEMAddItemViewController *)controller didSaveItemWithName:(NSString *)name andQuantity:(float)quantity andPrice:(float)price andCategory:(NSString *)category andNotes:(NSString *)notes;
*/

- (void)didSaveItemWithName:(NSString *)name andQuantity:(float)quantity andPrice:(float)price andCategory:(NSString *)category andNotes:(NSString *)notes;

@end

@interface GEMAddItemViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>

@property (weak) id<GEMAddItemViewControllerDelegate> delegate;

@property NSArray *categories;

@end

任何有关如何纠正此问题的想法将不胜感激!!

最佳答案

你也可以这样做

@protocol GEMEditItemViewControllerDelegate;
@interface GEMEditItemViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>

@property GEMItem *item;
@property (weak) id<GEMEditItemViewControllerDelegate> delegate;

@end

@protocol GEMEditItemViewControllerDelegate <NSObject>
@required
- (void)controller:(GEMEditItemViewController *)controller didUpdateItem:(GEMItem *)item;
@end

关于ios - 自定义委托(delegate)找不到声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23100711/

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