gpt4 book ai didi

ios - -[UITableView _endCellAnimationsWithContext :] When trying to delete 中的 PFTableViewController 断言失败

转载 作者:行者123 更新时间:2023-11-29 01:52:00 25 4
gpt4 key购买 nike

从我的 PFTableViewController 中删除图像时出现此错误。我已经进行了广泛的搜索,据我所知,commitEditingStyle 中的代码是正确的。谁能帮忙?

import Foundation

class profileImageTableViewController:PFQueryTableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
@IBOutlet weak var MenuViewButton: UIBarButtonItem!
@IBOutlet weak var addImageButton: UIBarButtonItem!
let imagePicker = UIImagePickerController()


override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

// Configure the PFQueryTableView
self.parseClassName = "ProfileImages"
self.textKey = "pImage"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}

// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "ProfileImages")
var userid = PFUser.currentUser()?.objectId
query.whereKey("userid", equalTo: userid!)
query.whereKey("imageType", notEqualTo: "profileThumb")
query.orderByAscending("createdAt")
return query

}

override func viewDidLoad() {
super.viewDidLoad()
self.imagePicker.delegate = self
//println( myStruct )
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "imageCropSegue"{
if let destination = segue.destinationViewController as? profileImageCropView {
if let profileIndex = tableView.indexPathForSelectedRow()?.row {
var index = NSIndexPath(forRow: profileIndex, inSection: 0)
var cell = tableView.cellForRowAtIndexPath(index) as! profileImageCell
println(destination.profileImageView)
destination.profileImageView.image = cell.profileImageView.image //currently generates an error (separate issue)
}
}

}
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("profileImages") as! profileImageCell!
if cell == nil {
cell = profileImageCell(style: UITableViewCellStyle.Default, reuseIdentifier: "profileImages")
}
var iType = object["imageType"] as! String

//println(iType)
if iType == "profile"{
cell.profileImageButton.hidden = true
}

var file:PFFile = object["pImage"] as! PFFile
cell.profileImageView.image = UIImage(named: file.name)
cell.profileImageView.file = file
cell.profileImageView.loadInBackground(nil)
return cell
}

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
let objectToDelete = objects?[indexPath.row] as! PFObject
objectToDelete.deleteInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.loadObjects()
} else {
println(error)
}
}
}

}

@IBAction func addImageTapped(sender: UIBarButtonItem) {
if(self.objects?.count < 5){
self.imagePicker.allowsEditing = false
self.imagePicker.sourceType = .PhotoLibrary
self.imagePicker.modalPresentationStyle = .Popover
presentViewController(imagePicker, animated: true, completion: nil)
self.imagePicker.popoverPresentationController?.barButtonItem = sender
}else{
var alert = UIAlertController()
self.presentViewController(alert.isNotification("Max images reached", buttonText: "ok", preferredStyle: UIAlertControllerStyle.Alert), animated: true, completion: nil)
}

}


func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
var data:NSData = UIImageJPEGRepresentation(pickedImage, 0.5)
var imageFile = PFFile(name: "profileimage.jpg", data: data)
//imageView.contentMode = .ScaleAspectFill
//imageView.image = pickedImage
var myObject = PFObject(className: "ProfileImages")
myObject["authorised"] = false
myObject["userid"] = PFUser.currentUser()?.objectId!
myObject["imageType"] = "gallery"
myObject["pImage"] = imageFile
myObject.saveInBackgroundWithBlock{(success:Bool,error:NSError?) -> Void in
self.loadObjects()
}

}
dismissViewControllerAnimated(true, completion: nil)
}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}

当我运行模拟器时,图像从解析中删除,但一旦发生这种情况,我就会收到错误。

https://drive.google.com/file/d/0Bxds5-29-lhIR0I3MGswdFE1LUU/view?usp=sharing

这里是 loadObjects() 的断点

最佳答案

我遇到了完全相同的问题。

最后,我意识到我忘记在重新加载 tableView 之前从“objects”中删除“objectToDelete”。

关于ios - -[UITableView _endCellAnimationsWithContext :] When trying to delete 中的 PFTableViewController 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31297207/

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