我已将方法声明为:
- (void) authorizeUser:(OauthObject *) user withUsername: (NSString *) username withPassword: (NSString *) password completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error)) CallCompletion;
我尝试调用此方法,如下所示:
[[ManagerServerRequest sharedManagerServerRequest] authorizeUser:(OauthObject *) withUsername:self.login.text withPassword:self.login.text completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// TODO
}]
其中 ManagerServerRequest sharedManagerServerRequest
是单例对象。
我收到错误:
使用未声明的标识符 WithUsername
如何正确调用该方法?
评论:
我通过oauthObj
:
OauthObject* oauthObj = [[OauthObject alloc] init];
[[ManagerServerRequest sharedManagerServerRequest]
authorizeUser: oauthObj and:
withUsername:self.login.text
withPassword:self.login.text
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// TODO
}]
我可能会出错
最佳答案
该问题与 block 语法无关。在你的代码中
[[ManagerServerRequest sharedManagerServerRequest]
authorizeUser:(OauthObject *)
withUsername:self.login.text
withPassword:self.login.text
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// TODO
}]
您缺少 authorizeUser:
的实际参数,将 (OauthObject *)
替换为实际对象即可。
关于ios - 如何在 Object C 中使用 block 调用方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34722984/