Strange Delay to Update TextField

前端 未结 1 1414
离开以前
离开以前 2021-01-27 12:19

Im getting Facebook User Data to auto completing signup textfields.

Problem: I did a test and NSLog returns information quickly, but to update the TextFields.text it\'s

1条回答
  •  悲哀的现实
    2021-01-27 13:02

    You need to perform UI updates on the main thread. Your completion handler is being called on a background thread.

    [meRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    
        if (!error) {
            NSDictionary *resultsDictionary = [responseData objectFromJSONData];
    
            NSLog(@"%@", [resultsDictionary objectForKey:@"name"]);
    
            // The problem is here. While NSLog runs in seconds showing Facebook User Name, the textfiend.text updates take about 10 seconds longer.
    
            // Ensure UI updated on main queue
            dispatch_async(dispatch_get_main_queue(), ^{
                _tfName.text = [resultsDictionary objectForKey:@"name"];
                _tfEmail.text = [resultsDictionary objectForKey:@"email"];
                _tfGender.text = [resultsDictionary objectForKey:@"gender"];
                _tfBirthday.text = [resultsDictionary objectForKey:@"birthday"];
            });
        }
    
    }];    
    

    0 讨论(0)
提交回复
热议问题