2016-07-06 66 views
-1

嗨,我一直在使用解析和快速制作应用程序,并试图删除解析以及在屏幕上的单元格。我主要在这里尝试了一切,但它不起作用。请帮忙。继承人的代码:删除表格视图单元格与解析swift

import UIKit 

class TableViewController: PFQueryTableViewController { 

    // Sign the user out 
    @IBAction func signOut(sender: AnyObject) { 

     PFUser.logOut() 

     let storyboard = UIStoryboard(name: "Main", bundle: nil) 
     let vc = storyboard.instantiateViewControllerWithIdentifier("SignUpInViewController") as! UIViewController 
     self.presentViewController(vc, animated: true, completion: nil) 
    } 

    @IBAction func add(sender: AnyObject) { 

     dispatch_async(dispatch_get_main_queue()) { 
      self.performSegueWithIdentifier("TableViewToDetailView", sender: self) 
     } 
    } 

    // Initialise the PFQueryTable tableview 
    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 = "Posts" 
     self.textKey = "nameEnglish" 
     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: "Posts") 
     query.orderByAscending("nameEnglish") 
     return query 
    } 

    //override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell { 

     var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! PFTableViewCell! 
     if cell == nil { 
      cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell") 
     } 

     // Extract values from the PFObject to display in the table cell 
     if let nameEnglish = object?["nameEnglish"] as? String { 
      cell.textLabel?.text = nameEnglish 
     } 
     if let capital = object?["capital"] as? String { 
      cell.detailTextLabel?.text = capital 
     } 

     return cell 
    } 

    // In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

     // Get the new view controller using [segue destinationViewController]. 
     var detailScene = segue.destinationViewController as! DetailViewController 

     // Pass the selected object to the destination view controller. 
     if let indexPath = self.tableView.indexPathForSelectedRow { 
      let row = Int(indexPath.row) 
      detailScene.currentObject = (objects?[row] as? PFObject) 
     } 
    } 

    override func viewDidAppear(animated: Bool) { 

     // Refresh the table to ensure any data changes are displayed 
     tableView.reloadData() 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     tableView.reloadData() 
     tableView.reloadInputViews() 
    } 

} 
+0

这里没有任何代码试图删除任何东西 – Paulw11

+0

我知道我问我怎么做,因为一切尝试不对应。任何想法如何做到这一点? @ Paulw11 –

+0

你想要删除哪个单元格 - 它是如何识别的? – CoolPenguin

回答

1

你的任务伊桑,你应该选择接受它....哈哈我不得不说。

您想从PFQueryTableViewController中移除单元格。所以,你可以使用像这样:

斯威夫特

override func tableView(tableView: UITableView, 
    commitEditingStyle editingStyle: UITableViewCellEditingStyle, 
     forRowAtIndexPath indexPath: NSIndexPath) { 
    if (editingStyle == .Delete) { 
     removeObjectAtIndexPath(indexPath) 
    } 
} 

Objective-C的

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

if (editingStyle == UITableViewCellEditingStyleDelete) { 

    PFObject *object = self.objects[indexPath.row]; 
    object[@"hidden"] = @YES; 
    [object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){ 

     if (!error) { 

      [self removeObjectAtIndexPath:indexPath animated:YES]; 
      [self loadObjects]; 


     } else { 

...你的代码的其余部分

但像其他人那样表示Parse正在关闭,因此您可能需要考虑Firebase或Parse Server 。

祝你好运伊桑。

+0

也是Ethan你应该编辑你的问题或者更改代码或者一些东西。你会让很多人把你的问题打倒。 – MattWright

+0

哈哈好吧,非常感谢你,只是有一个问题。当我尝试你的代码看起来不错,但告诉我没有这样的事情,“removeObjectAtIndexPath” –