【问题标题】:Delete single items from parse array从解析数组中删除单个项目
【发布时间】:2015-12-26 10:23:19
【问题描述】:

我正在尝试从我的 Parse 数组中删除项目。任何想法我做错了什么?

func deletePhoto(sender:UIButton) {
    let i : Int = (sender.layer.valueForKey("index")) as! Int
    let image = facebookPics[i]
    PFUser.currentUser()?.removeObject(facebookPics[i], forKey: "images")
    PFUser.currentUser()?.saveInBackground()
    facebookPics.removeAtIndex(i)
    self.mainCollectionView!.reloadData()

}

当我在UICollectionViewCell 中按下UIButton 时,就会发生这种情况。它将它从我的阵列中删除,其余的进展非常顺利。 解析有什么问题?

【问题讨论】:

  • 您的 collectionview 从哪里获取数据? reloadData() 是否会触发您的应用再次从 Parse 获取其数据,并且您希望图像不会被获取?
  • reloadData() 只是用来重新排列单元格。它不会触发查询。我只是想从我的 Parse-Data 中删除对象
  • 我的问题不是关于 reloadData() 本身,而是你的 collectionview 从哪里获取数据...根据你的数据最初来自哪里,对 reloadData 的调用可能会触发 Parse 的新获取。请说明您的 collectionview 数据来自哪里。
  • 啊,我明白了。它在 viewDidLoad() 方法中触发。

标签: ios arrays swift parse-platform


【解决方案1】:

找到答案:

问题基本上是,我需要重新登录,因为我的 PFUser.currentUser 为 nil。

代码还是不错的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-19
    • 2021-01-28
    • 1970-01-01
    • 2021-10-03
    • 2014-09-21
    • 1970-01-01
    • 2013-06-08
    • 2020-07-01
    相关资源
    最近更新 更多