0

无法理解在这种情况下出了什么问题,所以我不能使用委托 - 有一个例外self.plistManager.delegate = self; Property 'delegate' not found on object of type 'DataPlistManager *'

#import "DataManager.h"
#import "DataPlistManager.h"

@interface DataAdapter : NSObject <DataStorageManager>

@property (nonatomic,strong) DataPlistManager *plistManager;
- (void) saveFile;

@end

及其实施

#import "DataAdapter.h"

@implementation DataAdapter

-(id) initWithDataPlistManager:(DataPlistManager *) manager
{
    self = [super init];
    self.plistManager = manager;
    self.plistManager.delegate = self;
    return self;
}

- (void) saveFile
{
    [self.plistManager savePlist];
}

@end
4

3 回答 3

0

您的 DataPlistManager 需要一个属性委托:

@property (weak) id<DataStorageManager> delegate;
于 2013-09-06T05:50:25.897 回答
0

DataManager 类包含委托属性,因此您应该将对象设置为 DataManager 类的委托,并在委托类中调用方法(发送消息) saveFile:

@implementation DataAdapter

- (void)someMethod) {
    DataManager *dataManagerObject = [[DataManager alloc] init];
    dataManagerObject.delegate = self;
}

@implementation DataManager

- (void)someDelegateMethod {
    [self.delegate saveFile];
}

您确定您了解委托模式的概念吗?

https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html

于 2013-09-06T06:27:45.027 回答
0

如果您#import "DataAdapter.h""DataPlistManager.h"文件中添加然后将其删除并将其添加到"DataPlistManager.m"文件中,我不知道,但几天前我有同样的问题,我通过使用这个技巧解决了它:)

于 2013-09-06T05:58:18.290 回答