Я хочу запросить с помощью Parse, чтобы добавить строки в массив. Затем я хочу поместить эти строки в ячейки моего UITableView. Однако каждый раз, когда я запускаю приложение, на моем столе ничего не появляется. Вот мой код, если кто-то может помочь объяснить некоторые из причин, по которой он может не отображатьсяUITableView Swift вопросы
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) {
}
Итак, что я могу сделать, чтобы исправить это? – Justin
Подобно этому же вопросу вчера. Они используют асинхронный код только в другом месте. http://stackoverflow.com/questions/30361517/asynchronous-tableviewcell-data/30361658#30361658. Принципы и варианты решения схожи. – Gruntcakes
Im confused, как я могу убедиться, что Im работает функция CellforRowAtIndexPath после ViewdidLoad, потому что я думаю, что ViewDidLoad или даже ViewDidAppear произойдут сначала. – Justin