iOS应用程序,表视图
有人能帮帮我吗!我正在使用Xcode版本6.4开发一个使用swift语言的应用程序,我想从解析中检索数据“子信息”并将数据存储在表中,我还想在从表中选择子项后编辑“子信息”,这是我运行它时的代码模拟器屏幕在显示项目名称后变黑iOS应用程序,表视图,ios,swift,uitableview,parse-platform,Ios,Swift,Uitableview,Parse Platform,有人能帮帮我吗!我正在使用Xcode版本6.4开发一个使用swift语言的应用程序,我想从解析中检索数据“子信息”并将数据存储在表中,我还想在从表中选择子项后编辑“子信息”,这是我运行它时的代码模拟器屏幕在显示项目名称后变黑 import UIKit import Parse class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { @IBOutlet var tblchild
import UIKit
import Parse
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet var tblchild:UITableView!
override func viewDidLoad() {
super.viewDidLoad()
var childQuery=PFQuery(className:"Child")
//run the query
childQuery.findObjectsInBackgroundWithBlock {
(success,error) -> Void in
if let objects=success{
for object in objects{
var str:String?{
if let name=object["childName"]{return "\(name)" }
return ""
}
var name=object["childName"]
var unwrappedName=""
if let name=name{
unwrappedName="\(name)"
}
}
self.tblchild.reloadData()
}//end loop
}//end the first if
}//end of the find objects
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//override func viewWillAppear(animated: Bool) {
// tblchild.reloadData();
// }
//UITableViewDataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return child.children.count
}
//bulding cell
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Default")
cell.textLabel?.text=child.children[indexPath.row].name
return cell
}
}
我不知道解析,但我建议在执行任何其他操作之前,确保表视图连接正确。首先注释掉
findobjectsinbackgroundithblock
,然后从numberOfRowsInSection
返回0
。运行时,将显示一个空白表视图。如果可行,那么创建一个简单的模型,比如一个带有一个字符串的数组,返回myArray.count
在numberOfRowsInSection
中,并相应地调整cellforrowatinexpath()
。当您运行时,您应该看到您的字符串,并且您可以确信表视图已正确连接。从那开始,代码看起来很混乱,没有冒犯的意思。在完成块的中间计算变量<代码> STR < /代码>?如果让name=name,请避免使用可选的绑定语法。如果让unwrappedName=name应该是,
非常感谢Murray&Vadian,,Murray black simulator仍然显示为Vadian,您能告诉我如何一步一步地检索和存储数据吗请我不熟悉Parse
,但通常您在后台和完成块中检索数据-主要是一组字典-您必须在重新加载之前更新数据源桌子。在您的例子中,应该更新child.children
对象。您也在从主线程调用reloadData,我怀疑这也会导致问题。