Search code examples
iosobjective-cuitableviewnsurlconnection

iOS NSURLConnection doesn't call connectionDidFinishLoading


I have a UIViewController with UITableView.

In my viewDidLoad method I call NSURLConnection:[[NSURLConnection alloc]initWithRequest:request delegate:self].

After this, I assume, NSURLConnectionDelegate methods such as didReceiveResponse should be called. My idea is to get data and to fill table with it.

But actually, after NSURLConnection call, UITableViewDataSource methods are called before didReceiveResponse method. Because of this, I can't initialise table view with new data.

Why? How to fix it?

Thank you very much!


Solution

  • Assuming you had an array with the elements you have to show on your UITableView

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        // Update data from the response to your elements array
        ...
    
        // Reload Data
        [self.tableView reloadData];
    }