【发布时间】:2015-07-30 23:52:37
【问题描述】:
我正在以这种方式从“_User”类中检索数据:
我的声明..
var userIds = [String]()
var userNames = [String]()
var profilePics = [PFFile]()
var gender = [String]()
var userQuery = PFUser.query()
userQuery?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects {
self.userIds.removeAll(keepCapacity: true)
self.userNames.removeAll(keepCapacity: true)
self.profilePics.removeAll(keepCapacity: true)
for object in objects {
if let user = object as? PFUser {
if user.objectId != PFUser.currentUser()?.objectId {
self.userIds.append(object["objectId"] as! userListTableViewCell) // getting an error here.. "unexpectedly found nil while unwrapping an Optional value"
self.userNames.append(object["fullName"] as! String!)
self.profilePics.append(object["profilePicture"] as! PFFile!)
self.gender.append(object["gender"] as! String!)
}
}
self.tableView.reloadData()
}
}
})
]1
当我点击用户“Rfdfbd”的关注按钮时,“取消关注”标题也会自动出现在用户“Ihbj.....”上:/我该如何解决这个问题??
我的 IBAction followButton 代码在这里:
@IBAction func followButtonTapped(sender: UIButton) {
println(sender.tag)
sender.setTitle("unfollow", forState: UIControlState.Normal)
let getOjbectByIdQuery = PFUser.query()
getOjbectByIdQuery!.whereKey("objectId", equalTo: userIds[sender.tag])
getOjbectByIdQuery!.getFirstObjectInBackgroundWithBlock { (foundObject: PFObject?, error: NSError?) -> Void in
if let object = foundObject {
var followers:PFObject = PFObject(className: "Followers")
followers["user"] = object
followers["follower"] = PFUser.currentUser()
followers.saveEventually()
}
}
}
我在这里使用 sender.tag 作为关注按钮..
【问题讨论】:
-
这似乎您在不同的单元格中有相同的按钮引用。这就是为什么您更新按钮内容它会影响按钮引用的所有位置。
-
你能详细说明你的答案吗??
标签: ios swift uitableview parse-platform