2012-08-29 251 views
1

我有一个Dropbox API的问题。我正在开发另一个开发人员开发的大型应用程序。现在我要清理代码。所有委托方法(loadedMetadata & Co.)都直接在视图中。现在我想将它们提取到自己的课堂中。所以我创建了一个DropboxService类,其中包含所有的方法。所以我有了视图并从DropboxService中调用了方法loadMetadata。这个方法被调用并且很好。但Delegate方法loadedMetadata从不调用。Dropbox委托方法不被调用

我做了什么错误/我必须改变什么才能正确工作?

Dropbox的服务有DBRestClientDelegate为“超类”(不知道是怎么回事我究竟叫)

@interface DropboxService : CloudProviderService <DBRestClientDelegate> { 
} 

编辑:

该服务被实例化在AppDelegate中和是一个变量有:

- (DropboxService *)getDropboxService { 
    if (self.dropboxService == nil) { 
     self.dropboxService = [[DropboxService alloc] init]; 
    } 
    return self.dropboxService; 
} 

来自德国

铝问候exander

+1

你实例客户端,并指定其委托你能提供的代码? –

+0

'DBRestClientDelegate'不是“超类”。你可以说'DropboxService' _adopts_'DBRestClientDelegate' _guotocol_ – fguchelaar

+0

fguchelaar:谢谢 CarlVeazey:你是什么意思“分配它的代表? –

回答

0

您还需要从该接口

@interface DBRestClient : NSObject { ... id<DBRestClientDelegate> delegate; 
+0

dropboxService还没有一个名为Delegate的属性,我应该创建它吗?它必须是哪种类型? –

+0

协议需要被“告知”它将触发回调的对象。这是通过将委托分配给该对象来实现的。这是你失踪的一步。应该有一个委托财产的地方。 – Vlad

+0

Dropbox Session有一个委托,这是DropboxService DBSession * session = [DBSession alloc]; [session initWithAppKey:CONSUMER_KEY appSecret:SECRET_KEY root:kDBRootDropbox]; 会议。委托=自我; // DBSessionDelegate方法允许你处理重新认证 [DBSession setSharedSession:session]; –

0

这头犯规说DropboxService是一个子类的DBRestClientDelegate

它说,设置初始化

DBRestClient.delegate = self; 

后委托DropboxService符合协议DBRestClientDelegate

Dropbox示例项目解释了所有这些,但是您想要查找设置的位置DBRestClient并确保DropboxService已成为该实例的代表。

这是它看起来像我的代码符合DBRestClientDelegate

- (DBRestClient*)restClient { 
    if (restClient == nil) { 
     restClient = [((DBRestClient *)[DBRestClient alloc]) initWithSession:[DBSession sharedSession]]; 
     restClient.delegate = self; 
    } 
    return restClient; 
} 
+0

好的,我发现错误:在视图中有一个restClient.delegate =自我行左....所以委托总是回到视图...我改变它,现在它正在工作......谢谢! –

+0

你能解释一下你是否解决了这个问题,因为我有同样的问题。 – BDGapps