我不想做的例子:
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
}
我知道在 numberOfRowsInSection 它返回 0 导致 sendAsynchronousRequest 在之后执行,但是有没有办法让 numberOfRowsInSection 函数在 sendAsynchronousRequest 之后执行?或者有没有更好的方法让我的变量在 numberOfRowsInSection 函数之前等于 5?