如何在对象C中调用带方法的方法?

时间:2016-01-11 13:40:43

标签: ios objective-c

我已将方法声明为:

- (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是单身对象。

我收到错误: use undeclared identifier 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
 }]

我可以错误

2 个答案:

答案 0 :(得分:1)

该问题与阻止语法无关。在你的代码中

[[ManagerServerRequest sharedManagerServerRequest] 
    authorizeUser:(OauthObject *) 
    withUsername:self.login.text 
    withPassword:self.login.text 
    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        // TODO
}]

您错过了authorizeUser:的实际参数,将(OauthObject *)替换为实际对象,您就可以了。

答案 1 :(得分:0)

代码无法编译,但这就是你在问题中所说的: - )

从错误消息中,当您使用withUsername时,看起来您正在使用WithUsername。

相关问题