Example of what i wan't to do:
var b = 0
let URL: NSURL = NSURL(string: "[URL to php file]")!
let request:NSMutableURLRequest = NSMutableURLRequest(URL: URL)
request.HTTPMethod = "POST"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(response, data, error) in
b = 5
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return b //Return 0
}
I know that in numberOfRowsInSection it return 0 cause the sendAsynchronousRequest execute after but is there a way to make the numberOfRowsInSection function execute after the sendAsynchronousRequest ? Or is there a better way to make my variable equal 5 before numberOfRowsInSection function?
You don't want to delay the
numberOfRows...
call, but you can calltableView.reloadData
once you've received the data in your asynchronous request:That will make the table view reconfigure itself and call
numberOfRows...
again.