I’m trying to get rows from a UITableView that have been marked by the user and then save them as Parse relations to the current user.
Here is the code for the IBAction (Save button) and the function:
@IBAction func saveButton(sender: AnyObject) {
getCheckmarkedCells(tableView: UITableView,indexPath: NSIndexPath)
}
func getCheckmarkedCells(tableView: UITableView, indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .Checkmark {
let checkedCourse = cell.textLabel?.text
var query = PFQuery(className: "Courses")
query.whereKey("coursename", equalTo: checkedCourse!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
}
}
} else {
// Log details of the failure
println("Error")
}
}
}
}
I get an error in line 2:
Cannot invoke 'getCheckmarkedCells' with an argument list of type '(tableView: UITableView.Type, indexPath: NSIndexPath.Type)‘
What am I doing wrong?
EDIT:
// Configure cells for Checkmarks
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .Checkmark
{
cell.accessoryType = .None
}
else
{
cell.accessoryType = .Checkmark
}
}
}
EDIT2:
import UIKit
import Parse import ParseUI
class KurseTableViewController: PFQueryTableViewController {
// 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 = "Courses"
self.textKey = "coursename"
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: "Courses")
query.orderByDescending("coursename")
return query
}
var selectedRows = NSMutableIndexSet()
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if (self.selectedRows.containsIndex(indexPath.row)) {
cell.accessoryType = .None
self.selectedRows.removeIndex(indexPath.row)
} else {
cell.accessoryType = .Checkmark
self.selectedRows.addIndex(indexPath.row);
}
}
}
@IBAction func saveButton(sender: AnyObject) {
//getCheckmarkedCells(tableView: UITableView indexPath: NSIndexPath)
}
/*func getCheckmarkedCells(tableView: UITableView, indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .Checkmark {
let checkedCourse = cell.textLabel?.text
var query = PFQuery(className: "Courses")
query.whereKey("coursename", equalTo: checkedCourse!)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
}
}
} else {
// Log details of the failure
println("Error")
}
}
}*/
}
EDIT3:
@IBAction func saveButton(sender: AnyObject) {
let currentUser = PFUser.currentUser()
var selectedObjects = Array<PFObject>()
let cUserRel = currentUser?.relationForKey("usercourses")
for object in qObjects {
cUserRel!.removeObject(object as! PFObject)
}
println(selectedRowSets)
for selectedRows in self.selectedRowSets {
println("count")
selectedRows.enumerateIndexesUsingBlock(
{(index, stop) -> Void in
// Get object reference
if self.objects != nil{
let anObject = self.objects![index] as! PFObject
selectedObjects.append(anObject)
println(anObject)
cUserRel!.addObject(anObject)
}
})
}
currentUser?.save()
navigationController?.popViewControllerAnimated(true)
}