【发布时间】:2014-10-27 02:38:20
【问题描述】:
我有两种方法,我需要使用第一个变量作为第二个的输入参数。我该怎么做?我的代码是:
第一种方法
-(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 在调用[self getResponseData:apiHttp]; 之后是null,即使我的方法返回它。
【问题讨论】:
标签: objective-c variables methods