2012-08-29 77 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