我有一个场景,用户将输入 PINCode 号码,我必须将该号码作为参数传递给 Webservices API(用户是一个单例类),然后我将获得一个位置数组作为响应,并且我应该在 A lable 中显示该响应在 PINCode 的文本字段下方。所以我的理解是我必须在该方法中创建一个带有完成块的方法。但我的疑问是如何让位置数组在标签中表示。我真的很困惑,我试过这个
API.h
+(void)submitPINCode:(NSInteger *)pinCode CompletionBlock:(void(^)(BOOL status, NSArray * responseArray))handler;
API.m
+(void)submitPINCode:(NSInteger *)pinCode CompletionBlock:(void(^)(BOOL, NSArray *))handler
{
NSString *string = [NSString stringWithFormat:@"%@%@",URL,pinCode];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
operation.responseSerializer = [AFXMLParserResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
BOOL status = NO;
if (operation.response.statusCode == kStatusCodeSuccessfullResponse) {
status = YES;
// here we have to send an array so make the response object in to array or create a response Dictionary as you wish
NSArray *responseArray = (NSDictionary *)responseObject;
}
handler(status,BfErrorCodeUnknownError, responseArray);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSInteger statusCode = operation.response.statusCode;
BfErrorCode errorCode = BfErrorCodeUnknownError;
if (statusCode == kStatusCodeNoInternetConnection) {
errorCode = BfErrorCodeNetworkError;
}
NSString *errorMessage = [NSString stringWithBfErrorCode:errorCode];
handler(NO,errorCode,nil); // here if nil is doesnt work just pass an empty array instead of nil create an array and pass it
}];
// [operation start];
}
所以我的疑问是:
1)我是在以正确的方式前进,或者我必须做哪些改变才能得到答案,并且
2)天气我必须创建类方法或实例方法?对于这些情况,我必须在哪里创建类和实例方法?