【发布时间】:2014-12-04 14:39:19
【问题描述】:
我正在使用查询从 parse.com 中提取一个对象数组。我有 NsLog 语句显示我正在正确地从解析中检索数据,但是当我尝试迭代这些对象并将信息放入我的 tableview 用作它的源的数组中时,什么都没有显示。这是我的代码:
class FunListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet var tableView: UITableView!
var funlists = [String]()
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
// Do any additional setup after loading the view, typically from a nib.
var query = PFQuery(className: "FunLists")
query.whereKey("createdBy", equalTo:"Sean Plott")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
NSLog("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects {
NSLog("%@", object.objectId)
self.funlists.append(object.objectId)
}
} else {
// Log details of the failure
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.funlists.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel!.text = self.funlists[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("You selected cell #\(indexPath.row)!")
}
}
【问题讨论】:
标签: ios iphone uitableview swift parse-platform