【问题标题】:Dropbox Delegate methods not being called未调用 Dropbox 委托方法
【发布时间】:2012-08-30 17:21:38
【问题描述】:

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

我做错了什么/我必须改变什么才能让它正常工作?

Dropbox 服务将 DBResClientDelegate 作为“超类”(不知道我到底是怎么称呼它的)

@interface DropboxService : CloudProviderService <DBRestClientDelegate> {
}

编辑:

Service 在 AppDelegate 中实例化并且是一个变量:

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

来自德国的问候

亚历山大

【问题讨论】:

  • 您能否提供实例化客户端并分配其委托的代码?
  • DBRestClientDelegate 不是“超类”。你可以说DropboxService adopts DBRestClientDelegate protocol
  • fguchelaar:谢谢 CarlVeazey:“分配其代表”是什么意思?
  • 你必须在某处分配请求的委托,它在哪里设置?比如,request.delegate = someobject; 周围的代码是什么样的?

标签: objective-c ios delegates dropbox-api


【解决方案1】:

你还需要在初始化之后设置委托

DBRestClient.delegate = self;

从此界面

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

【讨论】:

  • dropboxService 还没有一个名为 Delegate 的属性,我应该创建它吗?它必须是哪种类型?
  • 需要“告知”协议将触发回调的对象。这是通过将委托分配给该对象来实现的。那是您缺少的步骤。某处应该有一个委托属性。
  • Dropbox Session 有一个委托,这是 DropboxService DBSession *session = [DBSession alloc]; [会话 initWithAppKey:CONSUMER_KEY appSecret:SECRET_KEY root:kDBRootDropbox]; session.delegate = 自我; // DBSessionDelegate 方法允许你处理重新认证 [DBSession setSharedSession:session];
  • @interface DBRESTClient : NSObject { ... id 委托; ...这是您需要设置的。
【解决方案2】:

该标题没有说DropboxService 是DBRestClientDelegate 的子类

它说DropboxService符合DBRestClientDelegate的协议

Dropbox 示例项目解释了所有这些,但您想查找在哪里设置 DBRestClient 并确保将 DropboxService 设为该实例的委托。

这就是我的代码中的样子,它符合DBRestClientDelegate

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

【讨论】:

  • 好的我发现了错误:在视图中有一个restClient.delegate = self line left....所以代理总是被设置回视图...我改变了它现在它正在工作...谢谢!
  • 能否请您解释一下您为解决问题所做的工作,因为我遇到了同样的问题。
猜你喜欢
  • 1970-01-01
  • 2011-08-12
  • 1970-01-01
  • 2015-06-09
  • 2016-07-16
  • 2019-01-04
相关资源
最近更新 更多