请有人帮助我。我已经被困了一个多星期,试图修复这些错误,搜索到但都没有成功。
我很抱歉,如果这是一个简单的解决方案,但我真的浪费了很多时间添加和更改东西但无济于事。任何帮助将非常感激:)
//更新:为Userviewcontroller添加了完整的代码,也非常感谢你的回复我很感激:))
import UIKit
import Parse
class UserTableViewController: UITableViewController {
var users = [""]
var following = [Bool]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
println(PFUser.currentUser())
var query = PFUser.query()
query!.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]!, error: NSError!) -> Void in
self.users.removeAll(keepCapacity: true)
for object in objects {
var user:PFUser = object as! PFUser
var isFollowing:Bool
if user.username != PFUser.currentUser().username {
self.users.append(user.username)
isFollowing = false
var query = PFQuery(className:"followers")
query.whereKey("follower", equalTo:PFUser.currentUser().username)
query.whereKey("following", equalTo:user.username)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for object in objects {
isFollowing = true
}
self.following.append(isFollowing)
self.tableView.reloadData()
} else {
// Log details of the failure
println(error)
}
}
}
}
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
println(following)
return users.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
if following.count > indexPath.row {
if following[indexPath.row] == true {
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
}
}
cell.textLabel?.text = users[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
if cell.accessoryType == UITableViewCellAccessoryType.Checkmark {
cell.accessoryType = UITableViewCellAccessoryType.None
var query = PFQuery(className:"followers")
query.whereKey("follower", equalTo:PFUser.currentUser()!.username!)
query.whereKey("following", equalTo:cell.textLabel!.text!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for object in objects {
object.deleteInBackground()
}
} else {
// Log details of the failure
println(error)
}
}
} else {
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
var following = PFObject(className: "followers")
following["following"] = cell.textLabel?.text
following["follower"] = PFUser.currentUser()!.username
following.saveInBackground()
}
}
}
//我正在接受":
无法调用' findObjectsInBackgroundWithBlock'带参数列表 类型'(([AnyObject]!,NSError!) - > Void)"
错误我已经尝试了每个建议的解决方案和代码更改堆栈溢出这是让我疯狂请帮助。我也在另一条线上得到同样的东西:(
我试图切换!至 ?几乎你能想到的一切。我猜它很容易解决。
我将非常感谢修复
答案 0 :(得分:0)
请参阅this answer。
原因:在swift 1.2中更改了选项(Xcode 6.3更新)
答案 1 :(得分:-1)
根据这个question,您应该调用的函数是:
query!.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]!, error: NSError!) in
your code ...
})
因此,您必须从函数调用中删除-> Void
。