我想運行一個查詢來確定Swift中tableView中的行數。當我使用的查詢results.count方法我收到以下錯誤:Int不能轉換爲Swift中的void tableView
Int? is not convertible to 'Void'
下面是引發錯誤的功能:如果我改變(results: [AnyObject]?, error: NSError?) -> Void
到(results: [AnyObject]?, error: NSError?) -> Int
我得到一個
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let user = self.user {
var currentUserQuery = PFQuery(className: "Game")
currentUserQuery.whereKey("user1", equalTo: PFUser.currentUser()!)
currentUserQuery.whereKey("isActive", equalTo: true)
var currentUserQuery2 = PFQuery(className: "Game")
currentUserQuery2.whereKey("user2", equalTo: PFUser.currentUser()!)
currentUserQuery2.whereKey("isActive", equalTo: true)
var query = PFQuery.orQueryWithSubqueries([currentUserQuery, currentUserQuery2])
query.findObjectsInBackgroundWithBlock{
(results: [AnyObject]?, error: NSError?) -> Void in
if error != nil {
println(error)
}
if error == nil{
//continue an active game that already exists with the user
if results != nil{
return results!.count as? Int
不同的錯誤:
Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject]?, NSError?) -> Int)'
我該怎麼辦?
謝謝!
你不能使用同步方法返回它 –
感謝您的回覆!您有推薦的解決方法嗎? – winston
填充您的表格視圖或在取回您的信息後重新加載它。 –