vendredi 27 février 2015

Passing data from a UITableView cell to another VC's UITableView? (Swift)

I'm basically trying to pass data from a UITableView's cell, from one viewcontroller to my second viewcontroller when deleting a cell from the first viewcontroller.


Here's the code for my first viewcontroller class trying to pass the tableview data to an Array in my other viewcontroller class:



var deletedProperty: [String] = []
var storedDeletion: [String] = []

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

if(editingStyle == UITableViewCellEditingStyle.Delete){
storedDeletion.append(deletedProperty[indexPath.row])
taskMgr.tasks.removeAtIndex(indexPath.row)
tblTasks.reloadData();
}

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "YourIdentifier" {
let destination = segue.destinationViewController as ThirdViewController; destination.secondTaskMgr = storedDeletion
}
}


Here's the code for my other viewcontroller class containing the Array:



var secondTaskMgr: SecondTaskManager = SecondTaskManager()

struct secondTask {
var passedName = ""
}

class SecondTaskManager: NSObject {
var secondTasks = [secondTask]()

func secondAddTask(name: String){
secondTasks.append(secondTask(passedName: name))
}
}


In the first viewcontroller class I get the error "'NSArray' is not a subtype of 'ThirdViewController.SecondTaskManager'" at



let destination = segue.destinationViewController as ThirdViewController; destination.secondTaskMgr = storedDeletion


What's the issue here and how do I fix it? And is there any better way to do this?




Aucun commentaire:

Enregistrer un commentaire