【发布时间】:2015-05-21 20:26:09
【问题描述】:
我想使用 Parse 进行查询以将字符串添加到数组中。然后我想将这些字符串放入我的 UITableView 的单元格中。但是,每次我运行该应用程序时,我的桌子上似乎都没有出现任何内容。如果有人可以帮助解释它可能不会出现的一些原因,这是我的代码
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var friendsArray: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
var usrname = currentUser?.username
var query = PFQuery(className:"Relation")
query.whereKey("Sender", equalTo : usrname!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
//println("Successfully retrieved \(objects) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
var friendName = object["Friend"] as! String
println(friendName)
self.friendsArray.append(friendName)
}
}
}
else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return friendsArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
cell.textLabel?.text = self.friendsArray[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
【问题讨论】:
标签: ios uitableview swift parse-platform