0

I'm trying to get data and show in tableView. As I have to send Request in viewDidLoad. But it took much time while loading my data, so I need it to be done in async way. Any Suggestions or Recommendations.?

- (void)viewDidLoad {

    //------castApi----//
    [super viewDidLoad];
    [[self tableView2]setDelegate:self ];
    [[self tableView2]setDataSource:self];
    array=[[NSMutableArray alloc]init];
    NSString *castString = [NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@/credits?api_key=c4bd81709e87b12e609433c49",movieIDinString];
    NSURL *url=[NSURL URLWithString:castString];

    NSURLRequest *request=[NSURLRequest requestWithURL:url];
    connection=[NSURLConnection connectionWithRequest:request delegate:self];
    if (connection){
        webData=  [[NSMutableData alloc]init];
    }
}
vaibhav
  • 4,038
  • 1
  • 21
  • 51

1 Answers1

0

Try this

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@/credits?api_key=c4bd81709e87b12e609433c49",movieIDinString]];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{

}];
KKRocks
  • 8,222
  • 1
  • 18
  • 84