我有兩個方法,我需要使用第一個變量作爲第一個輸入參數。我該怎麼做?我的代碼是:如何獲得從方法返回的變量
第一種方法
-(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];
被稱爲即使我的方法反駁它。