AFNetworking을 사용하여 내 앱의 배경에 표시 할 이미지를로드하려고합니다. 문제는 viewDidLoad
이미지로드를 호출 할 때, AFNetworking이 데이터 로딩을 완료하지 않았기 때문에 표시되지 않습니다.AFNetworking 2.0 & Background Image
여기 내 코드. AFNetworking
:
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// 3
NSDictionary *user = (NSDictionary *)responseObject;
NSString *backurlJSON=[user valueForKeyPath:@"back_url"][0];
NSLog(@"Background from Start: %@",backurlJSON);
if(![backurlJSON isEqualToString:@""]){
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.mydomain.com/images/%@", backurlJSON]];
NSData *data = [[NSData alloc]initWithContentsOfURL:url ];
imgBack = [[UIImage alloc]initWithData:data ];
backgroundView = [[UIImageView alloc] initWithImage: imgBack];
는 그래서 viewDidLoad
에 내가 UIImageView
이미지를로드 하위 뷰를 가지고, 경우에로드 할 이미지를 내가 하나가 에서 오는 덮어 쓰기를 좋아하는 것,이 없다 AFNetworking.
의 viewDidLoad :
background = [UIImage imageNamed: @"2.png"];
backgroundView = [[UIImageView alloc] initWithImage: background];
backgroundView.frame = CGRectMake(-10, -10, 340, 588);
backgroundView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:backgroundView];
어떤 생각 방법이 작업을 수행하려면?
이 작품은 완벽하게 고마워요! –