我有两个方法,我需要使用第一个变量作为第一个输入参数。我该怎么做?我的代码是:如何获得从方法返回的变量
第一种方法
-(NSString*)getResponseData :(NSString*) apiHttp {
NSString *code = @"&code=";
NSString *finalLink = [[NSString alloc] initWithFormat:@"%@%@",apiHttp,phoneNumber];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:finalLink]];
NSLog(@"%@", finalLink);
__block NSDictionary *json;
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
json = [NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];
NSLog(@"Async JSON: %@", json);
NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
myString = [jsonDict objectForKey:@"result"];
// NSLog(@"%@", myString);
}];
return myString;
}
方法二:
-(void)showCodeView:(NSString*) ifString{
if([ifString isEqualToString:@"200"]){
aPasswordField.hidden = NO;
[aPasswordField setBorderStyle:UITextBorderStyleLine];
aPasswordField.layer.cornerRadius=1.0f;
aPasswordField.layer.masksToBounds=YES;
aPasswordField.layer.borderColor=[[UIColor whiteColor]CGColor];
aPasswordField.layer.borderWidth= 0.8f;
UIColor *color = [UIColor lightTextColor];
aPasswordField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Код" attributes:@{NSForegroundColorAttributeName: color}];
self.aPasswordField.delegate = self;
}
}
这是我怎么称呼他们:
[self getResponseData:apiHttp];
[self showCodeView:myString];
所以我不明白为什么我的myString
是null
后[self getResponseData:apiHttp];
被称为即使我的方法反驳它。