gpt4 book ai didi

ios - 从解析错误中删除信息

转载 作者:行者123 更新时间:2023-11-28 09:00:55 25 4
gpt4 key购买 nike

我正在构建一个应用程序,允许用户查看应用程序中的内容以及向 Parse 数据库添加信息和删除信息。

在我的 Parse 核心中,我有一个名为“信息”的类,其中包含名为“标题”和“详细信息”的列。

我使用两个数组在 TableView 中显示数据:titleArray 和 detailArray。

这是我重新加载信息的方式,但是在删除 tableView 中的最后一项时它似乎失败了。

func reloadData () {




var query = PFQuery(className:"information")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in

if error == nil {

self.titleArray.removeAll()
self.detailArray.removeAll()


if let objects = objects as? [PFObject] {

for object in objects {


if let stringTitle = object.objectForKey("title") as? String {

self.titleArray.append(stringTitle)


if let stringDetail = object.objectForKey("detail") as? String {
self.detailArray.append(stringDetail)


self.tableView.reloadData()

}
}

}


} else {

var errorAlert = UIAlertController(title: "Failed to Retrieve Data", message: ("Error: \(error!)"), preferredStyle: .Alert)

errorAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))

self.presentViewController(errorAlert, animated: true, completion: nil)





}
}


}


}

如果我在应用程序中打开另一个 View Controller 然后返回,一切正常,但如果我运行 viewDidLoad 方法它仍然有错误。

请帮帮我!我将不胜感激。

最佳答案

我认为你必须在删除成功后重新加载 tableView 并从你的数据源中删除项目

objectToDelete.deleteInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// Force a reload of the table — update your datasource first
titleArray.removeAtIndex(row)
detailArray.removeAtIndex(row)
self.reloadData()
} else {
// There was a problem, check error
}

关于ios - 从解析错误中删除信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32058244/

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