对象:AFNetworking中的数据在viewDidLoad中的所有内容后加载......?

时间:2017-09-05 05:32:35

标签: ios objective-c

我在AFNetworking请求中的ViewController中加载数据。但是,执行此操作会导致该方法内部的数据在我的viewDidLoad中的所有其他内容都已加载后加载2-3秒。 为什么? 如何才能使这些数据同时出现在屏幕上?我已经在堆栈上看到了这个问题的一些变体,并且没有任何建议的修复似乎对我有用。请参阅下面的代码。

ViewController.m

 NSMutableDictionary *viewParams = [NSMutableDictionary new];
    [viewParams setValue:@"map" forKey:@"view_name"];
    [DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {

        dispatch_async(dispatch_get_main_queue(), ^{
        self.mapuserData = (NSMutableArray *)responseObject;

        [self.tableView reloadData];


        [operation responseString];

        if ([self.mapuserData count] > 0 ) {

                NSString *thisUserId = [self.mapuserData objectForKey:@"users_name"];


                NSPredicate *predicate = [NSPredicate predicateWithFormat:@"node_title CONTAINS[cd] %@",
                                          thisUserId];

                NSArray *resultArray = [self.acceptedFriends filteredArrayUsingPredicate:predicate];
                NSLog(@"RESULT %@", resultArray);

                if ([resultArray count] > 0) {
                    NSLog(@"Executed!");
                    self.addFriend.hidden = YES;
                    self.orangeFriendCircle.hidden = YES;
                } else {

                    self.addFriend.hidden = NO;
                    self.orangeFriendCircle.hidden = NO;

                }

                self.username.text = self.mapuserData[@"users_name"];

                self.userBio.text = self.mapuserData[@"userbio"];

                NSString *thirdLink = self.mapuserData[@"photo_path"];

                NSString *ImageURLTwo = thirdLink;
                NSData *imageDataTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURLTwo]];

                self.userPhoto.image = [[UIImage alloc] initWithData:imageDataTwo];

                self.supervisionLabel.text = [self.mapuserData objectForKey:@"supervision"];

                self.propertyLabel.text = [self.mapuserData objectForKey:@"property type"];

                self.childrenLabel.text = [self.mapuserData objectForKey:@"children"];

                self.specialLabel.text = [self.mapuserData objectForKey:@"special skills"];

                self.emergencyLabel.text = [self.mapuserData objectForKey:@"emergency"];

                self.username.text = [self.mapuserData objectForKey:@"first name"];

                self.userBio.text = [self.mapuserData objectForKey:@"userbio"];
        });

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Failure: %@", [error localizedDescription]);
    }];

0 个答案:

没有答案