gpt4 book ai didi

ios - 所有未在 UITableView 中呈现的解析对象

转载 作者:行者123 更新时间:2023-11-28 07:01:48 25 4
gpt4 key购买 nike

我正在从解析中的关系中检索对象。我想要的对象已成功检索并打印在输出框中,但是当我运行该应用程序时,我的 UITable 仅显示六个对象之一。关于如何让所有这些都出现在我的观点上有什么建议吗?我将不胜感激。

 class MyGroupsHomePage: UITableViewController {

let cellidentifer = "MyGroupsCell"


var mygroupsdata: NSMutableArray = NSMutableArray()

func findcurrentuserobjects () {
var currentuser = PFUser.query()
currentuser!.whereKey("username", equalTo: PFUser.currentUser()!.username!)
currentuser!.findObjectsInBackgroundWithBlock { (object:[AnyObject]?, error: NSError?) -> Void in
if error == nil && object != nil {

if let object = object as? [PFObject] {

for objects in object {

self.mygroupsdata.addObject(objects)
}

}
}

self.tableView.reloadData()

}


}



override func viewDidLoad() {
super.viewDidLoad()

findcurrentuserobjects()



}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.mygroupsdata.count
}

var groupnamearray: NSMutableArray = NSMutableArray()
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellidentifer, forIndexPath: indexPath) as! UITableViewCell
let mygroupdata: PFObject = self.mygroupsdata.objectAtIndex(indexPath.row) as! PFObject
let relation = mygroupdata.relationForKey("UserGroups")
let query = relation.query()
query?.findObjectsInBackgroundWithBlock({ (objet:[AnyObject]?, erro: NSError?) -> Void in

if erro == nil && objet != nil {

if let objet = objet as? [PFObject] {

for objets in objet {
println(objets.objectForKey("GroupName")!)
cell.textLabel?.text = objets.objectForKey("GroupName")! as? String

}

}

} else {

println("Error, could not retrieve user groups \(erro)")

}



})


return cell
}








}

最佳答案

作为Paulw11声明,这是问题所在:

for objets in objet {
println(objets.objectForKey("GroupName")!)
cell.textLabel?.text = objets.objectForKey("GroupName")! as? String
}

您不断更新同一个 textLabel 中的相同属性“文本”,我假设它是 UITableViewCell 子类中的一个 IBOutlet,您可以使用它来定义单元格的外观。在不了解您希望如何布置此文本的情况下,很难提出答案。一种快速而肮脏的方法可能是(我还没有测试过):

for objets in objet {
println(objets.objectForKey("GroupName")!)
let obj = objets.objectForKey("GroupName")! as? String
let newString = "\(obj) "
cell.textLabel?.text = "\(cell.textLabel?.text)\(newString)"
}

但是,根据您想要实现的目标,您可能需要向 UITableViewCell 子类添加 subview (在 Storyboard中的单元格原型(prototype)上或以编程方式)。

关于ios - 所有未在 UITableView 中呈现的解析对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31846535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com